چگونه برای پیکربندی یک آدرس IP استاتیک در لینوکس

مراحل زیر CentOS را با یک آدرس IP ثابت پیکربندی می کند.

  1. رابط شبکه ای را که می خواهید آدرس IP ثابت را روی آن تنظیم کنید ، بررسی کنید.
    ip addr

    Linux Network Interface Output

  2. Here we are setting network interface enp0s8 to be static. We need to edit the corresponding file in the path /etc/sysconfig/network-scripts . The file for interface enp0s8 است ifcfg-enp0s8 .

    sudo nano ifcfg-enp0s8
  3. The file needs to be changed from the following
    NAME="enp0s8"
    DEVICE="enp0s8"
    ONBOOT=yes
    NETBOOT=yes
    UUID="9ca41371-ee2d-4061-ab44-30bc06df3076"
    IPV6INIT=yes
    BOOTPROTO=dhcp
    TYPE=Ethernet

    Change the above to the following to make the interface use a static IP address. Additions are in green and amendments are in amber.

    IPADDR=192.168.56.222
    NETMASK=255.255.255.0
    GATEWAY=192.168.56.1
    NAME="enp0s8"
    DEVICE="enp0s8"
    ONBOOT=yes
    NETBOOT=yes
    UUID="9ca41371-ee2d-4061-ab44-30bc06df3076"
    IPV6INIT=yes
    BOOTPROTO=static
    TYPE=Ethernet

    Press Ctrl + X to save the file

  4. Restart the network service
    service network restart
  5. Verify the IP address
    ip addr