一、设置静态网络ip
1.编辑/etc/network/interfaces文件:
vi /etc/network/interfaces
# The primary network interface
auto em1 //有的是eth0
#iface em1 inet dhcp //dhcp自动的,将这行注释掉
在 interfaces文件加入下面的内容
iface eth0 inet static //static为静态的
address 192.168.1.105 //ip地址
netmask 255.255.255.0 //子网掩码
gateway 192.168.1.2 //网关
broadcast 192.168.1.2 //广播
2.编辑/etc/resolv.conf,设置相应的DNS
nameserver 202.96.134.133
#nameserver 8.8.8.8 //谷歌dns解析,但是速度较慢
3.重启网卡
/etc/init.d/networking restart
二、设置动态网络ip
1.编辑/etc/network/interfaces文件:
# The primary network interface
auto em1 //有的是eth0
iface em1 inet dhcp //dhcp自动的,将这行打开,其他的都注释掉
2. 重启网卡
/etc/init.d/networking restart
如果出现
stop: Job failed while stopping
start: Job is already running: networking
那么重启方法
ifdown em1 && ifup em1