1,自动获取IP的方法
自动获取与4个文件有关系
a),/etc/sysconfig/network-scripts/ifcfg-eth0
[zhangy@localhost network-scripts]$ cat ifcfg-eth0
# Marvell Technology Group Ltd. 88E8039 PCI-E Fast Ethernet Controller
DEVICE=eth0 //由eth0来启动
BOOTPROTO=dhcp //获取IP的方式是自动获取,static是固定IP,none是手动
HWADDR=00:16:D3:A2:F6:09 //网卡的物理地址
IPV6INIT=yes //是否支持IP6
IPV6_AUTOCONF=yes //IP6是否自动配置
ONBOOT=yes //启动时网络接口是否有效,我只改了这行重启后就可以了
b),/etc/sysconfig/network
[zhangy@localhost network-scripts]$ cat /etc/sysconfig/network
NETWORKING=yes //网络是否可用
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain//主机名,主机名在/etc/hosts里面配置
c),/etc/hosts
[zhangy@localhost network-scripts]$ cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost //根/etc/resolv.conf中search要对应,localhost.localdomain
::1 localhost6.localdomain6 localhost6
d),/etc/resolv.conf
[zhangy@localhost network-scripts]$ cat /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 192.168.1.1 //DNS服务器对应的IP
search localdomain//搜索要找的域名,在/etc/hosts里面设定的有
2,手动设定
手动设定只要修改三个文件就可以了
a),/etc/sysconfig/network
[zhangy@localhost network-scripts]$ cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
#HOSTNAME=localhost.localdomain //为什么要把主机名注释掉,一般先解析主机名或者域名,再解析DNS
GATEWAY=192.168.1.1 //加上网关
b),/etc/sysconfig/network-scripts/ifcfg-eth0
[zhangy@localhost network-scripts]$ cat ifcfg-eth0
# Marvell Technology Group Ltd. 88E8039 PCI-E Fast Ethernet Controller
DEVICE=eth0
BOOTPROTO=none //启动为手动
BROADCAST=192.168.1.255
HWADDR=00:16:D3:A2:F6:09
IPADDR=192.168.1.108 //设置的IP
NETMASK=255.255.255.0 //子网掩码
NETWORK=192.168.1.0
IPV6INIT=yes
IPV6_AUTOCONF=yes
ONBOOT=yes
TYPE=Ethernet //网络类型
c),/etc/resolv.conf
[zhangy@localhost network-scripts]$ cat /etc/resolv.conf
#; generated by /sbin/dhclient-script
#nameserver 192.168.1.1
#search localdomain
nameserver 116.228.111.118 //加上主DNS
nameserver 180.168.255.18 //加上次DNS