[root@caiyun ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 #第一块网卡逻辑设备名 HWADDR=00:0C:30:74:1D:12 #以太网硬件地址,即MAC地址 TYPE=Ethernet #上网类型,以太网 UUID=c6add3b0-aa22-41e7-9348-12e15c0302fc #通用惟一识别码,克隆的虚拟机没法启动能够去除此项 ONBOOT=yes #是否开机自动启动网卡 NM_CONTROLLED=yes #是否经过NetworkManager(网络管理器)管理网卡 BOOTPROTO=dhcp #获取IP方式,dhcp自动获取IP,还有none/bootp USERCTL=no PEERDNS=yes DNS1=8.8.8.8 #主DNS,默认会覆盖以及优先于/etc/resolv.conf NETMASK=255.255.255.0 #子网掩码 GATEWAY=10.0.0.254 #局域网网关地址 IPV6INIT=no #是否支持IPV6
网卡配置的DNS优先于/etc/resolv.conf的配置,而且会用eth0中的DNS覆盖/etc/resolv.conf,若是把eth0的DNS注释掉或者去掉,/etc/resolv.conf会恢复本身的DNS;bash
[root@caiyun ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-script search localdomain nameserver 192.168.61.2 #=原DNS配置 [root@caiyun ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes BOOTPROTO=dhcp HWADDR=00:0c:29:d2:0f:f6 DNS1=202.96.128.86 DNS2=8.8.8.8 USERCTL=no PEERDNS=yes IPV6INIT=no [root@caiyun ~]# /etc/init.d/network restart Shutting down interface eth0: [ OK ] Shutting down loopback interface: [ OK ] Bringing up loopback interface: [ OK ] Bringing up interface eth0: Determining IP information for eth0... done. [ OK ] [root@caiyun ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-script search localdomain nameserver 202.96.128.86 #重启网卡后/etc/resolv.conf中的DNS被覆盖 nameserver 8.8.8.8
网卡生效(重启):服务器
ifdown eth0 #停掉eth0网卡 ifup eth0 #启动eth0网卡
针对全部网卡:网络
/etc/init.d/network restart
blkid 查看磁盘的UUID:dom
[root@caiyun~]# blkid /dev/sda1: UUID="c88cfd42-8230-4837-a357-4ada772bf8fc" TYPE="ext4" /dev/sda2: UUID="f5da02de-7598-4721-bf7f-4305f7cc2343" TYPE="swap" /dev/sda3: UUID="5752a9aa-f90e-4ad3-a351-a74ba6514aea" TYPE="ext4"
修改主机名的步骤:oop
1)、hostname caiyun,修改后退出后再登入生效,可是服务器重启后失效。spa
2)、vi /etc/sysconfig/network rest
3)、vi /etc/hostsorm
配置默认网关: server
[root@caiyun ~]# route -n #查看路由配置 Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.79.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 192.168.61.2 0.0.0.0 UG 0 0 0 eth0 [root@ caiyun ~]# route del default gw 192.168.61.2 #删除网关 [root@ caiyun ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.61.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 [root@ caiyun ~]# ping www.baidu.com #删除以后不能上网 connect: Network is unreachable [root@ caiyun ~]# route add default gw 192.168.61.2 #添加网关 [root@ caiyun ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.61.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 192.168.61.2 0.0.0.0 UG 0 0 0 eth0 [root@ caiyun ~]# ping www.baidu.com PING www.a.shifen.com (163.177.151.109) 56(84) bytes of data. 64 bytes from 163.177.151.109: icmp_seq=1 ttl=128 time=10.8 ms 64 bytes from 163.177.151.109: icmp_seq=2 ttl=128 time=9.72 ms ^C