方法1:直接修改文件

列出所有网卡

  1. # ip a

或者

  1. # nmcli -p dev

编辑 ifcfg 文件

  1. # vi /etc/sysconfig/network-scripts/ifcfg-eth0

Update/edit as follows for static IP configuration:

  1. HWADDR=00:08:A2:0A:BA:B8
  2. TYPE=Ethernet
  3. BOOTPROTO=none
  4. # Server IP #
  5. IPADDR=192.168.2.203
  6. # Subnet #
  7. PREFIX=24
  8. # Set default gateway IP #
  9. GATEWAY=192.168.2.254
  10. # Set dns servers #
  11. DNS1=192.168.2.254
  12. DNS2=8.8.8.8
  13. DNS3=8.8.4.4
  14. DEFROUTE=yes
  15. IPV4_FAILURE_FATAL=no
  16. # Disable ipv6 #
  17. IPV6INIT=no
  18. NAME=eth0
  19. # This is system specific and can be created using 'uuidgen eth0' command #
  20. UUID=41171a6f-bce1-44de-8a6e-cf5e782f8bd6
  21. DEVICE=eth0
  22. ONBOOT=yes

重启网络服务

  1. # systemctl restart network

方法2:nmtui 图形界面

  1. # nmtui edit eth0

nmtui-edit-eth0.webp

验证 IP

Verify new IP settings:

  1. # ip a s eth0

Verify new routing settings:

  1. # ip r

Verify DNS servers settings:

  1. # cat /etc/resolv.conf

Verify the internet connectivity:

  1. # ping -c 3 cyberciti.biz
  2. # ping -c 4 google.com