Ubuntu 默认是DHCP自动获取IP。设定好静态IP,重启了也会变。
Ubuntu的网络配置信息是保存在 /etc/network/interfaces 文件中,使用Vim打开配置文件,默认是自动获取IP的配置.如下:
# The primary network interface
auto eth0
iface eth0 inet dhcp
下面我们将其设置成静态IP.
第一步:屏蔽掉自动获取IP的设置
iface eth0 inet dhcp将这一行屏蔽掉
修改之后的内容如下:
# The primary network interface
auto eth0
#iface eth0 inet dhcp
第二步:添加静态IP的信息
# The primary network interface
iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
1。设定IP
sudo gedit /etc/network/interfaces
auto lo
iface lo inet loopback #lo 是本地回环地址:127.1
auto eth0
iface eth0 inet static
address 192.168.1.152
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255 #设定eth0的IP
这样,IP并没有立即生效。
sudo /etc/init.d/networking restart
2。这时候就能ping到局域网中的电脑了。但是上不了Internet,是因为没有设置DNS的原因。DNS信息保存在/etc/resolv.conf中,一旦更改,立即生效。
sudo gedit /etc/resolv.conf
nameserver 208.67.222.222
nameserver 208.67.220.220
现在可以上网了。
附网卡设置相关命令:
查看网卡信息: ifconfig
设定一个网卡IP:ifconfig eth1 192.168.1.10 netmask 255.255.255.0
重启网卡使设定生效:sudo /etc/init.d/networking restart
Ubuntu的网络配置信息是保存在 /etc/network/interfaces 文件中,使用Vim打开配置文件,默认是自动获取IP的配置.如下:
# The primary network interface
auto eth0
iface eth0 inet dhcp
下面我们将其设置成静态IP.
第一步:屏蔽掉自动获取IP的设置
iface eth0 inet dhcp将这一行屏蔽掉
修改之后的内容如下:
# The primary network interface
auto eth0
#iface eth0 inet dhcp
第二步:添加静态IP的信息
# The primary network interface
iface eth0 inet static
address 192.168.0.10
netmask 255.255.255.0
gateway 192.168.0.1
1。设定IP
sudo gedit /etc/network/interfaces
auto lo
iface lo inet loopback #lo 是本地回环地址:127.1
auto eth0
iface eth0 inet static
address 192.168.1.152
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255 #设定eth0的IP
这样,IP并没有立即生效。
sudo /etc/init.d/networking restart
2。这时候就能ping到局域网中的电脑了。但是上不了Internet,是因为没有设置DNS的原因。DNS信息保存在/etc/resolv.conf中,一旦更改,立即生效。
sudo gedit /etc/resolv.conf
nameserver 208.67.222.222
nameserver 208.67.220.220
现在可以上网了。
附网卡设置相关命令:
查看网卡信息: ifconfig
设定一个网卡IP:ifconfig eth1 192.168.1.10 netmask 255.255.255.0
重启网卡使设定生效:sudo /etc/init.d/networking restart