1.IP/Netmask/Gateway的配置,啓動,與查看
- 修改配置文件
# vim /etc/sysconfig/network-scripts/ifcfg-enp0s25
修改或添加以下內容:
BOOTPROTO=none #其實只有關鍵字dhcp,手動配置可輸入static or none
ONBOOT=yes # 是否默認啓動此接口
IPADDR=10.122.22.115
NETMASK=255.255.252.0
GATEWAY=10.122.20.209
對於HWADDR(MAC),若僅有一張網卡,則可忽略。
-
重啓網絡接口,以更新更個網絡參數:
# /etc/init.d/network restart
-
查看配置是否正確
# Check 1: 查看IP參數是否正確,重點是IP與Netmask
[root@hanzo hanzo]# ifconfig enp0s25
enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.122.22.115 netmask 255.255.252.0 broadcast 10.122.23.255
inet6 fe80::23b2:d42:2c25:ba61 prefixlen 64 scopeid 0x20<link>
ether 3c:97:0e:3e:1c:89 txqueuelen 1000 (Ethernet)
RX packets 137456 bytes 15243468 (14.5 MiB)
RX errors 0 dropped 395 overruns 0 frame 0
TX packets 41 bytes 5857 (5.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 20 memory 0xf3500000-f3520000
# Check 2: 檢查路由定義是否正確
[root@hanzo hanzo]# route -n | grep enp0s25
0.0.0.0 10.122.20.209 0.0.0.0 UG 100 0 0 enp0s25
10.122.20.0 0.0.0.0 255.255.252.0 U 100 0 0 enp0s25
# U:代表路由可用;G:代表該網路需要經由Gateway來幫忙傳遞;H:代表該路由爲一臺主機,而非一整個網絡
# Check 3: 測試看看與路由之間是否能夠鏈接成功
[root@hanzo hanzo]# ping -c 3 10.122.20.209
PING 10.122.20.209 (10.122.20.209) 56(84) bytes of data.
64 bytes from 10.122.20.209: icmp_seq=1 ttl=255 time=0.492 ms
64 bytes from 10.122.20.209: icmp_seq=2 ttl=255 time=0.591 ms
64 bytes from 10.122.20.209: icmp_seq=3 ttl=255 time=0.510 ms
--- 10.122.20.209 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.492/0.531/0.591/0.043 ms
第三項檢查若失敗,可能是路由器關閉或Switch/Hub有問題,或是網線有錯誤以及防火牆配置錯誤。
2.DNS服務器IP的定義與查看
# vim /etc/resolv.conf
添加DNS Server IP:
nameserver xxx.xxx.xxx.xxx
Check 4:然後測試看所定義的DNS服務器能否提供域名解析:
# dig www.baidu.com
3.主機名的修改,啓動與查看
[root@hanzo hanzo]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=hanzo.net
[root@hanzo hanzo]# vim /etc/hosts
10.122.22.115 hanzo.net
因系統有很多服務已啓動,且需要主機名,都是到這個文件讀取的,所以修改完畢需要重新啓動。但是在重啓之前,需要進行以下操作,不然開機會花很長時間:
# 看看主機名有沒有對應的IP,如果沒有,開機流程會很慢
[root@hanzo hanzo]# hostname
hanzo.net
# Check 5: 檢查主機名是否有對應的IP
[root@hanzo hanzo]# ping -c 2 hanzo.net
PING hanzo.net (10.122.22.115) 56(84) bytes of data.
64 bytes from hanzo.net (10.122.22.115): icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from hanzo.net (10.122.22.115): icmp_seq=2 ttl=64 time=0.077 ms
--- hanzo.net ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.077/0.085/0.094/0.012 ms
修改過/etc/sysconfig/network裏的HOSTNAME後,務必重新啓動。
网友评论