Centos7.xのネットワーク設定を行う方法

2018年3月13日

1.ネットワーク設定
#cd /etc/sysconfig/network-scripts/
#mv ifcfg-eno16777728 ifcfg-eth0

インターフェース設定
#vim ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eth0 #name修正eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=172.16.8.250
PREFIX=24
GATEWAY=172.16.8.1
DNS1=114.114.114.114

2.grubの設定
追記 net.ifnames=0 biosdevname=0
#vim /etc/sysconfig/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=”$(sed ‘s, release .*$,,g’ /etc/system-release)”
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT=”console”
GRUB_CMDLINE_LINUX=”crashkernel=auto rd.lvm.lv=devops/root rd.lvm.lv=devops/swap rhgb net.ifnames=0 biosdevname=0 quiet”
GRUB_DISABLE_RECOVERY=”true”

#grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file …
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-cd4cedc54acd4c289771cd4af02255e8
Found initrd image: /boot/initramfs-0-rescue-cd4cedc54acd4c289771cd4af02255e8.img
done

3.再起動
#reboot
#ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.8.250 netmask 255.255.255.0 broadcast 172.16.8.255
inet6 fe80::20c:29ff:fe30:707a prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:30:70:7a txqueuelen 1000 (Ethernet)
RX packets 105 bytes 13994 (13.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 112 bytes 14592 (14.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 0 (Local Loopback)
RX packets 4 bytes 340 (340.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 4 bytes 340 (340.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0