0
5

More than 1 year has passed since last update.

LinuxにおけるIPv6のアドレスアサイン方法②

Posted at

概要

IPv6にはPrefix Delegation という上位ルータのPrefixの一部を下位ルータにPrefixごと払い出す機構がある。

環境

  • osxのmultipass上で動作するUbuntu20.04

DHCPv6-PDの検証

wan環境のPrefixの一部を下位のrouter環境に委譲する検証を行う。

  • OSSのインストール
sudo apt-get install -y dibbler-server radvd  dhcpcd5
  • 検証環境構築
sudo ip netns add lan
sudo ip netns add router
sudo ip netns add wan
sudo ip link add lan-veth0 type veth peer name gw-veth0
sudo ip link add wan-veth0 type veth peer name gw-veth1
sudo ip link set lan-veth0 netns lan
sudo ip link set wan-veth0 netns wan
sudo ip link set gw-veth0 netns router
sudo ip link set gw-veth1 netns router
sudo ip netns exec lan ip link set lan-veth0 up
sudo ip netns exec wan ip link set wan-veth0 up
sudo ip netns exec router ip link set gw-veth0 up
sudo ip netns exec router ip link set gw-veth1 up
  • カーネルパラメータの設定
    wan,routerにてIPv6フォワーディングを有効に設定。
    routerのwan側インタフェースRA受信有効、solicit送信有効に設定。
sudo ip netns exec wan sysctl -w net.ipv6.conf.all.forwarding=1
sudo ip netns exec router sysctl -w net.ipv6.conf.all.forwarding=1
sudo ip netns exec router sysctl -w net.ipv6.conf.gw-veth1.accept_ra=2
sudo ip netns exec router sysctl -w net.ipv6.conf.gw-veth1.router_solicitations=1
  • radvdの設定
    ステートレスでIPアドレスが設定されないようにする。
cat /etc/radvd.conf 
interface wan-veth0{
	AdvSendAdvert on;
	AdvManagedFlag on;        # Mフラグ On
	AdvOtherConfigFlag on;    # Oフラグ On
};
  • dibblerの設定
    isc-dhcpやwide-dhcpだとprefix64以外を払い出すことができなかった。(DHCPv6のシーケンスの途中で失敗する)
    このためDHCPv6ではdibblerを利用する。
    class,ta-classの定義はコメントアウトしpd-classを以下のように修正する。
    WANのルータが48のPrefixを上位から委譲され下位には56で払い出す設定。

sudo vi /etc/dibbler/server.conf 
#assign /96 prefixes from this pool
 pd-class {
     pd-pool 2001:db8:1100::/48
     pd-length 56
 }
  • radvdの起動
sudo ip netns exec wan sudo radvd
  • dibblerの起動
sudo ip netns exec wan dibbler-server start
  • dhcpクライアントの設定
    dhcpcdを用いる。wide-dhcpだとなぜか起動に失敗した(network namespace環境に対応していないのかもしれない)

以下をconfファイルに追記。

sudo vi /etc/dhcpcd.conf
noipv6rs
waitip 6
# Uncomment this line if you are running dhcpcd for IPv6 only.
#ipv6only

# use the interface connected to WAN
interface gw-veth1
ipv6rs
iaid 1
# use the interface connected to your LAN
ia_pd 1 gw-veth0
#ia_pd 1/::/64 LAN/0/64
  • dhcpクラアントの起動
 sudo ip netns exec router dhcpcd
DUID 00:04:af:e2:33:37:00:00:00:00:a1:bc:ed:f4:23:9e:23:a6
gw-veth0: IAID ce:aa:db:16
gw-veth1: IAID 00:00:00:01
gw-veth1: soliciting a DHCPv6 lease
gw-veth0: soliciting a DHCP lease
gw-veth1: ADV 2001:db8:1100:6000::/56 from fe80::84aa:eff:fe5f:3e78
gw-veth1: accepted reconfigure key
gw-veth1: REPLY6 received from fe80::84aa:eff:fe5f:3e78
gw-veth1: renew in 1800, rebind in 2700, expire in 7200 seconds
lo: adding reject route to 2001:db8:1100:6000::/56
gw-veth1: delegated prefix 2001:db8:1100:6000::/56
gw-veth0: adding address 2001:db8:1100:6003::1/64
gw-veth0: adding route to 2001:db8:1100:6003::/64
gw-veth1: soliciting a DHCP lease
gw-veth1: soliciting an IPv6 router
gw-veth1: Router Advertisement from fe80::84aa:eff:fe5f:3e78
gw-veth1: adding default route via fe80::84aa:eff:fe5f:3e78
gw-veth0: probing for an IPv4LL address
gw-veth1: probing for an IPv4LL address
gw-veth1: using IPv4LL address 169.254.124.101
gw-veth1: adding route to 169.254.0.0/16
gw-veth1: adding default route
forked to background, child pid 4084
  • IPアドレスを確認。
    LAN側のインタフェースにIPアドレスが付与されている。
    WAN側には付与されない(IPv6はグローバルアドレスなので WAN、LANそれぞれのインタフェースにIPアドレスを付与する意味がないから?)
sudo ip netns exec router ip a
1: lo:  mtu 65536 qdisc noop state DOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: gw-veth0@if4:  mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 2a:d6:ce:aa:db:16 brd ff:ff:ff:ff:ff:ff link-netns lan
    inet 169.254.198.159/16 brd 169.254.255.255 scope global noprefixroute gw-veth0
       valid_lft forever preferred_lft forever
    inet6 2001:db8:1100:6003::1/64 scope global dynamic noprefixroute 
       valid_lft 7180sec preferred_lft 3580sec
    inet6 fe80::28d6:ceff:feaa:db16/64 scope link 
       valid_lft forever preferred_lft forever
5: gw-veth1@if6:  mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 2a:48:77:06:fa:6c brd ff:ff:ff:ff:ff:ff link-netns wan
    inet 169.254.124.101/16 brd 169.254.255.255 scope global noprefixroute gw-veth1
       valid_lft forever preferred_lft forever
    inet6 fe80::2848:77ff:fe06:fa6c/64 scope link 
       valid_lft forever preferred_lft forever
  • 下位のLANには設定されたIPv6のPrefixを用いて、radvdやdhcpv6を起動することで、RAやRA+DHCPv6によるIPアドレスの払い出しをすることができる(はず)。

参考

0
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
5