直接修改Ubuntu IP系统配置文件
Ubuntu IP的网络配置文件是根目录下:/etc/network/interfaces
注意:修改完interfaces文档中的内容后,需要修改/etc/NetworkManager/NetworkManager.conf文档中的managed参数,使之为true,并重启。否则,会提示说“有线网络设备未托管”。
打开后里面可设置DHCP或手动设置静态IP。
前面auto eth0,表示让网卡开机自动挂载eth0。
1. 以DHCP方式配置网卡
编辑文件 /etc/network/interfaces
sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
#The primary network interface - use DHCP to find our address
auto eth0
iface eth0 inet dhcp
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart
也可以在命令行下直接输入下面的命令来获取地址sudo dhclient eth0
2. 为网卡配置静态Ubuntu IP地址
编辑文件 /etc/network/interfaces
sudo vi /etc/network/interfaces
并用下面的行来替换有关eth0的行:
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.2.1
gateway 192.168.2.254
netmask 255.255.255.0
#network 192.168.2.0
#broadcast 192.168.2.255
将eth0的IP分配方式修改为静态分配(static)后,为其制定IP、网关、子网掩码等信息。
将上面的Ubuntu IP地址等信息换成你自己就可以了。
用下面的命令使网络设置生效:
sudo /etc/init.d/networking restart