首先,习惯性的先配置hostname
[test@CentOS6 ~]$ sudo su -
[root@CentOS6 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=CentOS6.4
可以用vi编辑器激进型修改,如果需要实时生效,用hostname修改
[root@CentOS6 ~]# hostname CentOS6.4
修改网卡的配置,配置IP地址,子网掩码,网关
[root@CentOS6 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0c:29:ca:07:aa
TYPE=Ethernet
UUID=989a56e7-4028-4f7d-807c-9e88d6f3393d
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=2.2.2.5
NETMASK=255.255.255.0
DNS2=202.106.0.20
GATEWAY=2.2.2.1
DNS1=8.8.8.8
IPV6INIT=no
USERCTL=no
配置DNS
[root@CentOS6 ~]# more /etc/resolv.conf
nameserver 8.8.8.8
nameserver 202.106.0.20
查看系统路由表
[root@CentOS6 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
2.2.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 2.2.2.1 0.0.0.0 UG 0 0 0 eth0
用ping命令测试网络连通性
[root@CentOS6 ~]# ping baidu.com
PING baidu.com (220.181.57.216) 56(84) bytes of data.
64 bytes from 220.181.57.216: icmp_seq=1 ttl=128 time=15.3 ms
64 bytes from 220.181.57.216: icmp_seq=2 ttl=128 time=16.5 ms
^C
--- baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1869ms
rtt min/avg/max/mdev = 15.368/15.935/16.502/0.567 ms