主机名
查看
[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]#
临时修改
[root@localhost ~]# hostname centoscn
[root@localhost ~]# hostname
centoscn
[root@localhost ~]#
永久生效
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centoscn
host文件
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 #建议保留此行
10.15.72.194 localhost justin localhost6 localhost6.localdomain6 #必须有三个字段:IP、FQDN、HOSTNAME
IP配置
临时设置
[root@localhost ~]# ifconfig eth0 10.15.72.194 netmask 255.255.255.0
永久生效
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ls
ifcfg-eth0 ifdown-isdn ifup-aliases ifup-plusb init.ipv6-global
ifcfg-lo ifdown-post ifup-bnep ifup-post net.hotplug
ifdown ifdown-ppp ifup-eth ifup-ppp network-functions
ifdown-bnep ifdown-routes ifup-ippp ifup-routes network-functions-ipv6
ifdown-eth ifdown-sit ifup-ipv6 ifup-sit
ifdown-ippp ifdown-tunnel ifup-isdn ifup-tunnel
ifdown-ipv6 ifup ifup-plip ifup-wireless
[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth0bak #备份
[root@localhost network-scripts]# vim ifcfg-eth0
DEVICE=eth0 #指出设备名称
NM_CONTROLLED=yes#network mamager的参数,实时生效,不需要重启
ONBOOT=yes#设置为yes,开机自动启用网络连接
IPADDR=10.15.72.194 #IP地址
BOOTPROTO=static #设置为none禁止DHCP,设置为static启用静态IP地址,设置为dhcp开启DHCP服务
NETMASK=255.255.255.0 #子网掩码
DNS1=8.8.8.8 #第一个dns服务器
TYPE=Ethernet #网络类型为:Ethernet
GATEWAY=10.15.72.254 #设置网关
DNS2=8.8.4.4 #第二个dns服务器
IPV6INIT=no #禁止IPV6
USERCTL=no #是否允许非root用户控制该设备,设置为no,只能用root用户更改
HWADDR=00:0C:29:2C:E1:0F #网卡的Mac地址
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
NAME="System eth0"#定义设备名称
DEVICE、ONBOO、TBOOTPROTO、IPADDR、NETMASK、GATEWAY必须配置
单网卡设置双IP
[root@localhost network-scripts]# cp ifcfg-eth0 ifcfg-eth0:0
DEVICE=eth0:0
NM_CONTROLLED=yes
ONBOOT=yes
IPADDR=10.15.72.195
BOOTPROTO=static
NETMASK=255.255.255.0
DNS1=8.8.8.8
TYPE=Ethernet
GATEWAY=10.15.72.254
DNS2=8.8.4.4
IPV6INIT=no
USERCTL=no
HWADDR=00:0C:29:2C:E1:0F
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
NAME="System eth0:0"
Mac地址修改
[root@localhost network-scripts]# ifconfig eth0|grep HWadd
eth0 Link encap:Ethernet HWaddr 00:0C:29:81:38:08
[root@localhost network-scripts]# ifconfig eth0 down
[root@localhost network-scripts]#ifconfig eth0 hw ether 00:0C:29:28:28:28
[root@localhost network-scripts]# ifconfig eth0 | grep HWaddr
eth0 Link encap:Ethernet HWaddr 00:0C:29:28:28:28
[root@localhost network-scripts]# ifconfig eth0 up
路由
查看
[root@localhost network-scripts]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.15.72.0 * 255.255.255.0 U 1 0 0 eth0
default 10.15.72.254 0.0.0.0 UG 0 0 0 eth0
[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.15.72.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
0.0.0.0 10.15.72.254 0.0.0.0 UG 0 0 0 eth0
[root@localhost network-scripts]#
静态路由添加、删除
[root@localhost network-scripts]# route add -net 10.15.72.194/24 gw 10.15.72.254
[root@localhost network-scripts]# route del -net 10.15.72.194/24
默认网关添加、删除
[root@localhost network-scripts]# route add default gw 10.15.72.254
[root@localhost network-scripts]# route del default gw 10.15.72.254
网络节点测试
[root@localhost network-scripts]# traceroute 8.8.8.8
tracerouteto 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1 10.15.72.254 (10.15.72.254) 7.568 ms 7.880 ms 8.071 ms
网络连通性测试
[root@localhost network-scripts]# ping -c 5 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=2 ttl=46 time=32.3 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=46 time=31.8 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=46 time=33.4 ms
--- 8.8.8.8 pingstatistics ---
5 packets transmitted, 3 received, 40% packet loss, time5007ms
rtt min/avg/max/mdev= 31.891/32.554/33.458/0.662 ms
[root@localhost network-scripts]#
ARP信息
[root@localhost network-scripts]# arp -n #查看当前系统的ARP表Address HWtype HWaddress Flags Mask Iface10.15.72.254ether 08:d0:9f:e2:4d:c3 C eth010.15.72.73ether 00:25:64:a6:08:af C eth0[root@localhost network-scripts]# arp -s 10.15.72.25408:d0:9f:e2:4d:c3 #网关绑定ip和网关的mac[root@localhost network-scripts]# arp -d 10.15.72.73#删除arp记录
本文出自 “过程就是为了实现结果” 博客,请务必保留此出处http://justinpeng.blog.51cto.com/7662323/1302137