linux網卡、網關配置

[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
相關文章
相關標籤/搜索