安装系统时添加了两个网卡,安装完成后,网卡信息如下所示
root@ubuntu:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a
inet addr:10.180.0.189 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7486 errors:0 dropped:0 overruns:0 frame:0
TX packets:181 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:476030 (476.0 KB) TX bytes:19795 (19.7 KB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74
inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7375 errors:0 dropped:0 overruns:0 frame:0
TX packets:51 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:453195 (453.1 KB) TX bytes:8376 (8.3 KB)
想把eth0的ip配置成静态的10.180.141.130
打开网卡配置文件 vi /etc/network/interfaces
添加eth0的配置如下
auto eth0
iface eth0 inet static
address 10.180.141.130
netmask 255.255.255.0
gateway 10.180.0.1
保存后,重启网络
sudo /etc/init.d/networking restart
再查看网络配置 ifconfig
root@ubuntu:/etc/network# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a
inet addr:10.180.0.189 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38934 errors:0 dropped:0 overruns:0 frame:0
TX packets:187 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2371872 (2.3 MB) TX bytes:20377 (20.3 KB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74
inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:38823 errors:0 dropped:0 overruns:0 frame:0
TX packets:95 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2349037 (2.3 MB) TX bytes:11238 (11.2 KB)
发现网卡地址并没有变
注意:如果Ubuntu系统采用的是desktop版,由于desktop版安装了NetworkManager,修改完interfaces文档中的内容后,不会生效。需要先修改 /etc/NetworkManager/NetworkManager.conf 文档中的managed参数,使之为true,并重启系统, 然后在修改 /etc/network/interfaces 文件,设置静态IP。这是桌面版和服务器版的不同之处
root@tongfang-virtual-machine:~# cat /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq
[ifupdown]
managed=yes
root@tongfang-virtual-machine:~#
重启后,发现网卡配置正确了
root@ubuntu:/etc/network# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a
inet addr:10.180.141.130 Bcast:10.180.141.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2043569 errors:0 dropped:0 overruns:0 frame:0
TX packets:564 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:123158350 (123.1 MB) TX bytes:65430 (65.4 KB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74
inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20284 errors:0 dropped:0 overruns:0 frame:0
TX packets:232 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1252816 (1.2 MB) TX bytes:32046 (32.0 KB)
其实可以采用命令行的方式来配置ip地址
ifconfig eth0 10.180.141.130 netmask 255.255.0.0
查看网卡信息,发现信息正确,只是这种方式重启后网络配置不能保存
root@ubuntu:/etc/network# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:6a
inet addr:10.180.141.130 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e76a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:43771 errors:0 dropped:0 overruns:0 frame:0
TX packets:230 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2662710 (2.6 MB) TX bytes:27458 (27.4 KB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:ae:e7:74
inet addr:10.180.0.191 Bcast:10.180.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:feae:e774/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:43699 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2646716 (2.6 MB) TX bytes:11778 (11.7 KB)
至此,ip地址配置完毕。
配置dns请参考博主的下一篇博客