在CentOS系統中進行網絡配置通常涉及以下幾個步驟:
查看當前網絡配置:
使用 ip addr show
或者 ifconfig
命令(ip
命令是更現代的選擇)。
配置網絡接口:
使用 NetworkManager(CentOS 7及更高版本):
nmcli connection modify connection-name ipv4.method manual ipv4.addresses ip-address/subnet-mask ipv4.gateway gateway-ip
nmcli connection modify connection-name ipv4.dns dns-server
nmcli connection up connection-name
使用 ifcfg 文件(CentOS 6):
vi /etc/sysconfig/network-scripts/ifcfg-eth0
在文件中添加或修改以下內容:
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
保存并退出編輯器,然后重啟網絡服務:
service network restart
配置DNS:
編輯 /etc/resolv.conf
文件:
vi /etc/resolv.conf
添加以下內容:
nameserver 8.8.8.8
nameserver 8.8.4.4
保存并退出編輯器。
驗證網絡配置:
使用 ping -c 4 google.com
命令來驗證網絡配置是否正確。
通過以上步驟,你應該能夠在CentOS系統中成功進行網絡配置。