在CentOS系统中进行网络设置可以通过以下几种方法:
ip addr
进入配置文件所在目录
cd /etc/sysconfig/network-scripts
备份配置文件
cp ifcfg-ens33 myback
编辑配置文件
vi ifcfg-ens33
修改以下内容:
DEVICE=ens33
BOOTPROTO=static
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
ONBOOT=yes
重启网络服务
systemctl restart network
检查网络连接
ping www.baidu.com
nmcli device status
sudo nmcli connection modify "Wired connection 1" ipv4.method static
sudo nmcli connection up "Wired connection 1"
打开NetworkManager TUI
nmcli con show
sudo nmcli con up "Wired connection 1"
配置网络连接
/etc/sysconfig/network-scripts/ifcfg-eth0
文件sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0
添加或修改以下内容:
DEVICE=eth0
BOOTPROTO=static
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
ONBOOT=yes
/etc/network/interfaces
文件(适用于CentOS 7及以上版本)sudo vi /etc/network/interfaces
添加或修改以下内容:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
sudo systemctl restart networking
ifcfg-ensXX
或ifcfg-ethX
,其中XX
是网卡编号。通过以上步骤,您可以根据自己的需求选择合适的方法进行CentOS网络设置。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: centos message如何清理