Linux下设置IP、网关、掩码、MAC和DNS

先用ifconfig来查看所有活动网络接口

eth0      Link encap:Ethernet  HWaddr b8:27:eb:1b:63:a8
		inet addr:192.168.1.6  Bcast:192.168.1.255  Mask:255.255.255.0
		inet6 addr: fe80::6502:67ff:89b:b2fd/64 Scope:Link
		UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
		RX packets:43239 errors:0 dropped:24 overruns:0 frame:0
		TX packets:30644 errors:0 dropped:0 overruns:0 carrier:0
		collisions:0 txqueuelen:1000
		RX bytes:25068614 (23.9 MiB)  TX bytes:5993030 (5.7 MiB)

lo        Link encap:Local Loopback
		inet addr:127.0.0.1  Mask:255.0.0.0
		inet6 addr: ::1/128 Scope:Host
		UP LOOPBACK RUNNING  MTU:65536  Metric:1
		RX packets:1961 errors:0 dropped:0 overruns:0 frame:0
		TX packets:1961 errors:0 dropped:0 overruns:0 carrier:0
		collisions:0 txqueuelen:1
		RX bytes:160232 (156.4 KiB)  TX bytes:160232 (156.4 KiB)

设置IP和掩码

ifconfig eth0 192.168.1.6 netmask 255.255.255.0 

设置网关

route add default gw 192.168.1.1

修改网卡MAC

ifconfig eth0 down
ifconfig eth0 hw ether b877c322f8
ifconfig eth0 up

设置DNS

vi /etc/resolv.conf

nameserver 114.114.114.114
nameserver 114.114.115.115

重启网络服务生效 service network restart

最新的ubuntu已经不能简单通过修改/etc/resolv.conf来实现,需要修改resolvconf配置文件,然后通过命令resolvconf命令来操作

修改/etc/resolvconf/resolv.conf/目录下的head文件

nameserver 114.114.114.114

然后通过更新配置来生效

resolvconf -u
发布于