︿
Top

前言

最近工作關係開始又要回味 CentOS 了,在本次實作環境中採用的是 CentOS-6.8-x86_64-minimal.iso 映像檔,也就是 CentOS 6.8 最小化安裝版本 (Minimal Install)。為何不用最新的 CentOS 6.9 版本? 因為,最新的 LIS 4.1.3-2 僅支援至 CentOS 6.8,所以便以 CentOS 6.8 版本開始回味起了,那麼開始來玩玩吧。💪



實作環境




組態設定網路功能

建立好使用者帳號後接下來便是設定 CentOS 的網路功能,在本文設定中網路功能是以設定固定 IP 位址來進行說明。你可以透過 2 種方式設定固定 IP 位址,一為使用指令 system-config-network 來進行互動設定,另外一種方式則為手動將固定 IP 位址、網路遮罩等相關資訊寫入「/etc/sysconfig/network-scripts/ifcfg-eth0」網卡設定檔中,而預設閘道及主機名稱則是寫入「/etc/sysconfig/network」設定檔中,最後則是將 DNS 名稱解析資訊寫入「/etc/resolve.conf」設定檔中。
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none
IPADDR=10.10.75.8
NETMASK=255.255.255.0
IPV6INIT=no
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=centos68.weithenn.org
GATEWAY=10.10.75.254
# cat /etc/resolv.conf
search weithenn.org
nameserver 168.95.1.1
nameserver 8.8.8.8
# cat /etc/hosts
127.0.0.1 localhost
# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Determining if ip address 10.10.75.8 is already in use for device eth0...
[ OK ]

圖、組態設定固定 IP 位址

當 CentOS 主機的網路服務重新啟動並套用新的組態設定後,接著便可以使用 ping 指令來判斷主機是否能順利連上網際網路及進行名稱解析的動作,或者藉此判斷此台主機的網路通訊是卡在哪個環節上以便除錯。
# ping -c2 127.0.0.1   //檢查 Loopback
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.045 ms
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.024/0.034/0.045/0.012 ms
# ping -c2 10.10.75.8   //檢查固定 IP 位址
PING 10.10.75.8 (10.10.75.8) 56(84) bytes of data.
64 bytes from 10.10.75.8: icmp_seq=1 ttl=64 time=0.026 ms
64 bytes from 10.10.75.8: icmp_seq=2 ttl=64 time=0.047 ms
--- 10.10.75.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 0.026/0.036/0.047/0.012 ms
# ping -c2 10.10.75.254   //檢查 CentOS 與預設閘道之間的連線
PING 10.10.75.254 (10.10.75.254) 56(84) bytes of data.
64 bytes from 10.10.75.254: icmp_seq=1 ttl=128 time=0.774 ms
64 bytes from 10.10.75.254: icmp_seq=2 ttl=128 time=0.432 ms
--- 10.10.75.254 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1004ms
rtt min/avg/max/mdev = 0.432/0.603/0.774/0.171 ms
# ping -c2 8.8.8.8       //檢查 CentOS 是否能夠與指定的 DNS 伺服器連線
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=9.22 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=128 time=9.57 ms
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1012ms
rtt min/avg/max/mdev = 9.221/9.398/9.576/0.202 ms
# ping -c2 tw.yahoo.com   //檢查 CentOS 能否順利進行名稱解析
PING oob-media-router-fp1.prod.media.wg1.b.yahoo.com (106.10.178.36) 56(84) bytes of data.
64 bytes from media-router-fp1.prod.media.vip.sg3.yahoo.com (106.10.178.36): icmp_seq=1 ttl=128 time=89.1 ms
64 bytes from media-router-fp1.prod.media.vip.sg3.yahoo.com (106.10.178.36): icmp_seq=2 ttl=128 time=89.5 ms
--- oob-media-router-fp1.prod.media.wg1.b.yahoo.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1093ms
rtt min/avg/max/mdev = 89.173/89.382/89.592/0.365 ms

圖、檢查 CentOS 主機網路組態是否正確運作



CentOS 6.8 基礎設定系列文章

文章標籤: ,