温馨提示×

CentOS Minimal如何设置网络

小樊
43
2025-02-20 16:54:16
栏目: 智能运维
Centos服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在CentOS Minimal系统中设置网络,可以按照以下步骤进行:

方法一:使用nmcli命令行工具

  1. 安装NetworkManager(如果尚未安装):

    sudo yum install NetworkManager
    
  2. 启动并启用NetworkManager服务

    sudo systemctl start NetworkManager
    sudo systemctl enable NetworkManager
    
  3. 查看可用的网络连接

    nmcli connection show
    
  4. 添加新的网络连接(例如,添加一个静态IP地址):

    sudo nmcli connection add type ethernet ifname eth0 con-name myeth0 autoconnect yes ip4 192.168.1.100/24 gw4 192.168.1.1
    

    这里,eth0是你的以太网接口名称,myeth0是你给连接起的名字,192.168.1.100/24是IP地址和子网掩码,gw4 192.168.1.1是默认网关。

  5. 激活新连接

    sudo nmcli connection up myeth0
    
  6. 验证网络连接

    ping -c 4 google.com
    

方法二:手动编辑网络配置文件

  1. 找到网络接口配置文件: CentOS Minimal通常没有图形界面,网络配置文件位于/etc/sysconfig/network-scripts/目录下,文件名格式为ifcfg-<interface>,例如ifcfg-eth0

  2. 编辑网络接口配置文件

    sudo 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
    
  3. 重启网络服务

    sudo systemctl restart network
    
  4. 验证网络连接

    ping -c 4 google.com
    

注意事项

  • 确保你的网络接口名称(如eth0)是正确的。
  • 如果你使用的是无线网络,可能需要安装wireless-toolsiwconfig工具,并相应地配置无线网络。
  • 在生产环境中,建议使用静态IP地址,并确保配置文件的安全性。

通过以上步骤,你应该能够在CentOS Minimal系统中成功设置网络连接。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:CentOS Minimal配置步骤是什么

0