CentOS

CentOS7でIPを固定する

More than 3 years have passed since last update.


IPを固定する


/etc/sysconfig/network-scripts/ifcfg-enp3s0

 DEVICE="enp3s0"

ONBOOT=yes
NETBOOT=yes
UUID="0ebc2621-6086-4d9a-a15d-c52cdf6ade01"
IPV6INIT=no
-BOOTPROTO=dhcp
HWADDR="08:00:27:bf:e6:ec"
TYPE=Ethernet
NAME="enp3s0"

+BOOTPROTO=static
+DNS1="8.8.8.8"
+DNS2="8.8.4.4"
+DOMAIN=mydomain.com
+IPADDR=192.168.100.11
+NETMASK=255.255.255.0
+GATEWAY=192.168.100.1



IPを自動取得する場合


/etc/sysconfig/network-scripts/ifcfg-enp3s0

 DEVICE="enp3s0"

ONBOOT=yes
NETBOOT=yes
UUID="0ebc2621-6086-4d9a-a15d-c52cdf6ade01"
IPV6INIT=no
BOOTPROTO=dhcp
HWADDR="08:00:27:bf:e6:ec"
TYPE=Ethernet
NAME="enp3s0"
+DNS1="8.8.8.8"
+DNS2="8.8.4.4"


IPを固定しつつ自動取得もする


  • BOOTPROTO=dhcpがミソ


/etc/sysconfig/network-scripts/ifcfg-enp3s0

 DEVICE="enp3s0"

ONBOOT=yes
NETBOOT=yes
UUID="0ebc2621-6086-4d9a-a15d-c52cdf6ade01"
IPV6INIT=no
BOOTPROTO=dhcp
HWADDR="08:00:27:bf:e6:ec"
TYPE=Ethernet
NAME="enp3s0"

+DNS1="8.8.8.8"
+DNS2="8.8.4.4"
+DOMAIN=mydomain.com
+IPADDR=192.168.100.11
+NETMASK=255.255.255.0
+GATEWAY=192.168.100.1



/etc/sysconfig/network

NETWORKING="yes"

GATEWAYDEV="enp3s0"
NETWORKING_IPV6="no"
IPV6_DEFAULTDEV="enp3s0"
GATEWAY=192.168.100.1


/etc/hostname

dell.mydomain.com


設定反映

systemctl daemon-reload

systemctl restart network


IPv6を無効


/etc/sysctl.d/98-disableipv6.conf

net.ipv6.conf.all.disable_ipv6 = 1



/etc/sysconfig/network-scripts/ifcfg-enp3s0

- IPV6INIT=yes

+ IPV6INIT=no

reboot


確認

sysctl -a | grep disable_ipv6