注意:Ubuntu 12.04 版本为例
1. 设置IP
设置文件路径:/etc/network/interfaces
root@test01:~# vi /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
#这边的设置是本地回路
# The primary network interface
#eth0 就是网卡,如果电脑有多块网卡,比如还会有eth1……,都可以在这里进行设置。
auto eth0
#iface eth0 inet dhcp
#iface eth0 inet 设置为dhcp是动态获取IP,设置为static则用自定义的IP。这边要自定义IP地址,所以选择static选项。
iface eth0 inet static
#设置 IP地址
address 192.168.1.100
#设置掩码
netmask 255.255.255.0
#network 192.168.1.0
#broadcast 192.168.1.255
#设置网关
gateway 192.168.1.254
# dns-* options are implemented by the resolvconf package, if installed
#设置 DNS,和 /etc/resolv.conf 一致
dns-nameservers 192.168.1.1
dns-search localdomain
2.设置 DNS
ip设置好后,如果直接ping www.baidu.com会发现ping不通,因为dns还没设置,编辑/etc/resolv.conf,加上dns服务器地址。
root@test01:~#vi /etc/resolv.conf
nameserver 192.168.1.1
3.设置主机名
root@test01:~#vi /etc/hostname
test01
root@test01:~#hostname test01
4.重新启动网络服务:/etc/init.d/networking restart
重启好后,用ifconfig看下eth0,是不是改成自己需要的IP地址了。
root@test01:~#/etc/init.d/networking restart