ubuntu14下配置静态ip地址

安装系统时添加了两个网卡,安装完成后,网卡信息如下所示

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请参考博主的下一篇博客

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值