のぴぴのメモ

自分用のLinuxとかの技術メモ

KickStartその3(ネットワーク構成例 -vlan、bonding構成も)

0.関連記事一覧

1.はじめに

KickStarでosを自動インストールするときのネットワーク設定について、構成例をケース毎に説明します。vlan、bondや、vlanとbondを組み合わせた構成も説明します。

2.ネットワーク構成例

2.1静的IP構成

(1)構成イメージ

f:id:nopipi:20160802203126p:plain

(2)KickStart設定例

networkオプションで設定します。"--bootproto=static"とし、IPなど必要な設定を行います。

# Network information
network --bootproto=static --ip=10.0.2.15 --netmask=255.255.255.0 --gateway=10.0.2.2 --nameserver=192.168.11.1 --device=enp0s3 --noipv6 --activate
network --hostname=Server1

2.2DHCP設定の場合

(1)構成イメージ

f:id:nopipi:20160802203127p:plain

(2)KickStart設定例

networkオプションで、"--bootproto=dhcp"とします。

network --bootproto=dhcp --device=enp0s3 --noipv6 --activate
network --hostname=Server1

2.3複数セグメント設定

(1)構成イメージ

f:id:nopipi:20160802203128p:plain

(2)KickStart設定例

複数セグメントがある場合は、networkオプションを複数行記載します。

network --bootproto=dhcp --device=enp0s3 --noipv6 --activate
network --bootproto=static --device=enp0s8 --ip=192.168.0.20 --netmask=255.255.255.0 --nodefroute --nodns --noipv6 --activate
network --hostname=Server1

2.4VLAN設定

(1)構成イメージ

f:id:nopipi:20160802203129p:plain

(2)KickStart設定例

networkオプションで、"--vlanid="でVLAN IDを指定します。デバイス名を指定したい場合は、"--interfacename="を使います。未指定の場合は、"デバイス名.VLAN-ID"名称になります。

network --bootproto=dhcp --device=enp0s3 --noipv6 --activate
network --bootproto=static --device=enp0s8 --ip=192.168.0.20 --netmask=255.255.255.0 --nodefroute --nodns --noipv6 --activate
network --device=enp0s8 --vlanid=1000 --interfacename=enp0s8.1000 --bootproto=static --ip=192.168.10.20 --netmask=255.255.255.0 --nodefroute --nodns --noipv6 --activate
network --hostname=Server1

2.5bond設定(ネットワーク冗長化設定)

(1)構成イメージ

f:id:nopipi:20160802203130p:plain

(2)KickStart設定例

networkオプションでもbond構成を設定可能ですが、slaveデバイスがMacアドレス指定となるのが難点です。(LANカード交換によるmacアドレス変更後に設定変更が必要になるため)。slave指定をデバイス名(enp0s8とか)で指定するため、インストールの後処理(%post〜%endセクション)でNetworkManager(nmcliコマンド)で設定を作成し、インストールイメージにコピーする手段をとっています。post処理はNetworkManagerのデーモン経由の処理になるので、chrootを無効化して処理させます。

network --bootproto=dhcp --device=enp0s3 --noipv6 --activate
network --hostname=Server1
<中略>
%post --nochroot --log=/mnt/sysimage/root/ks-post-log.log

# delete enp0s8n and enp0s9 configuration file
nmcli c delete enp0s8
nmcli c delete enp0s9

# add a bond device
nmcli c add type bond ifname bond0 con-name bond0 mode active-backup miimon 100 updelay 600 primary enp0s8 
nmcli c mod bond0 ipv4.method manual ipv4.address "192.168.0.20/24" ipv4.never-default yes
nmcli c mod bond0 ipv6.method ignore ipv6.never-default yes
nmcli c add type bond-slave ifname enp0s8 con-name bond0-enp0s8 master bond0
nmcli c add type bond-slave ifname enp0s9 con-name bond0-enp0s9 master bond0

# copy network configurate files to the install image
rm -rf /mnt/sysimage/etc/sysconfig/network-scripts/ifcfg-*
cp -p /etc/sysconfig/network-scripts/ifcfg-* /mnt/sysimage/etc/sysconfig/network-scripts/

%end

2.6bond-vlan設定

(1)構成イメージ

f:id:nopipi:20160802203131p:plain

(2)KickStart設定例

応用です。bondデバイスを作成し、その上にVLANを設定する例です。

# Network information
network --bootproto=dhcp --device=enp0s3 --noipv6 --activate
network --hostname=Server1
<中略>
%post --nochroot --log=/mnt/sysimage/root/ks-post-log.log

# delete enp0s8n and enp0s9 configuration file
nmcli c delete enp0s8
nmcli c delete enp0s9

# add a bond device
nmcli c add type bond ifname bond0 con-name bond0 mode active-backup miimon 100 updelay 600 primary enp0s8
nmcli c mod bond0 ipv4.method disabled ipv6.method ignore
nmcli c add type bond-slave ifname enp0s8 con-name bond0-enp0s8 master bond0
nmcli c add type bond-slave ifname enp0s9 con-name bond0-enp0s9 master bond0

# add vlan devices(disable ipv4/v6 address)
nmcli c add type vlan ifname bond0.1000 con-name bond0.1000 dev bond0 id 1000
nmcli c mod bond0.1000 ipv4.method manual ipv4.address "192.168.10.20/24" ipv4.never-default yes
nmcli c mod bond0.1000 ipv6.method ignore

# copy network configurate files to the install image
rm -rf /mnt/sysimage/etc/sysconfig/network-scripts/ifcfg-*
cp -p /etc/sysconfig/network-scripts/ifcfg-* /mnt/sysimage/etc/sysconfig/network-scripts/

%end

2.7vlan-bond設定

(1)構成イメージ

f:id:nopipi:20160802203132p:plain

(2)KickStart設定例

上記の逆で、VLANデバイスを束ねてbondデバイスを構成する例です。あまり用途はないと思いますが。

network --bootproto=dhcp --device=enp0s3 --noipv6 --activate
network --hostname=Server1
<中略>
%post --nochroot --log=/mnt/sysimage/root/ks-post-log.log

# disable ipaddress at enp0s8n and enp0s9
nmcli c mod enp0s8 ipv4.method disabled ipv6.method ignore
nmcli c mod enp0s9 ipv4.method disabled ipv6.method ignore

# add vlan devices(disable ipv4/v6 address)
nmcli c add type vlan ifname enp0s8.1000 con-name enp0s8.1000 dev enp0s8 id 1000
nmcli c add type vlan ifname enp0s9.1000 con-name enp0s9.1000 dev enp0s9 id 1000
nmcli c mod enp0s8.1000 ipv4.method disabled ipv6.method ignore
nmcli c mod enp0s9.1000 ipv4.method disabled ipv6.method ignore

# add a bond device
nmcli c add type bond ifname bond0 con-name bond0 mode active-backup miimon 100 updelay 600 primary enp0s8.1000
nmcli c mod bond0 ipv4.method manual ipv4.address "192.168.10.20/24" ipv4.never-default yes
nmcli c mod bond0 ipv6.method ignore
nmcli c add type bond-slave ifname enp0s8.1000 con-name bond0-enp0s8.1000 master bond0
nmcli c add type bond-slave ifname enp0s9.1000 con-name bond0-enp0s9.1000 master bond0
nmcli c mod enp0s8.1000 connection.master bond0 connection.slave-type bond
nmcli c mod enp0s9.1000 connection.master bond0 connection.slave-type bond

# copy network configurate files to the install image
rm -rf /mnt/sysimage/etc/sysconfig/network-scripts/ifcfg-*
cp -p /etc/sysconfig/network-scripts/ifcfg-* /mnt/sysimage/etc/sysconfig/network-scripts/

%end