Table of Contents

, ,

Set up IPv6 on host and VM

Prerequisites:

  1. host with ipv6 subnet assigned
  2. kvm/qemu virtal machines

Host machine

Identify the interface to which to assign the ipv6. In case you are using a bridge you need to use the bridge interface.

Set up bridge (install bridge-utils package)

brctl addbr br0
ip link set up dev br0

Add physical interface to bridge, here eth2 (adjust as necessary):

brctl addif br0 eth2
# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.d05099fd8909       no              eth2
                                                        vnet0
                                                        vnet1
                                                        vnet2
                                                        vnet3
                                                        vnet4
                                                        vnet5
                                                        vnet6

Above we see the physical interface is eth2 and rest are vnets from created VMs from before.

Now add ipv6 to bridge interface.

If you just want to use the v6 address on the interface itself you have to remove it from the bridge.

We add the IP:

ip -6 addr add 2607:5300:203:9cc9::/64 dev br0

This is subnet so you can choose an ip like 2607:5300:203:9cc9::1234. In this example the above is equal to 2607:5300:203:9cc9::0 IP address.

Add route to the v6 gateway itself (get it from the server provider)

ip -6 route add 2607:5300:0203:9cff:00ff:00ff:00ff:00ff dev br0

then add default route:

ip -6 route add default via 2607:5300:0203:9cff:00ff:00ff:00ff:00ff

Check

# ip -6 r
::1 dev lo proto kernel metric 256 pref medium
2607:5300:203:9cc9::/64 dev br0 proto kernel metric 256 pref medium
2607:5300:203:9cff:ff:ff:ff:ff dev br0 metric 1024 pref medium
fe80::/64 dev eth2 proto kernel metric 256 pref medium
fe80::/64 dev vnet0 proto kernel metric 256 pref medium
fe80::/64 dev br0 proto kernel metric 256 pref medium
fe80::/64 dev vnet1 proto kernel metric 256 pref medium
fe80::/64 dev vnet2 proto kernel metric 256 pref medium
fe80::/64 dev vnet3 proto kernel metric 256 pref medium
fe80::/64 dev vnet4 proto kernel metric 256 pref medium
fe80::/64 dev vnet5 proto kernel metric 256 pref medium
fe80::/64 dev vnet6 proto kernel metric 256 pref medium
default via 2607:5300:203:9cff:ff:ff:ff:ff dev br0 metric 1024 pref medium

Inside of VM

Assign an ip from the IPv6 subnet of the host. We chose ..:178 here:

# ip -6 addr add 2607:5300:203:9cc9::178/64 dev eth0                                                                                      
# ip a                                
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00                                                                                                              
    inet 127.0.0.1/8 scope host lo                                                 
       valid_lft forever preferred_lft forever   
    inet6 ::1/128 scope host                                                       
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 02:00:00:a0:b6:a8 brd ff:ff:ff:ff:ff:ff              
    altname enp1s0                                                                 
    inet 51.161.64.178/32 scope global noprefixroute eth0        
       valid_lft forever preferred_lft forever               
    inet6 2607:5300:203:9cc9::178/64 scope global            
       valid_lft forever preferred_lft forever               
    inet6 fe80::ff:fea0:b6a8/64 scope link                   
       valid_lft forever preferred_lft forever

Now add default route. “via” is the IPv6 of the host interface br0.

# ip -6 route add default via 2607:5300:203:9cc9::0

# ping6 2001:4860:4860::8888                                                        
PING 2001:4860:4860::8888(2001:4860:4860::8888) 56 data bytes
64 bytes from 2001:4860:4860::8888: icmp_seq=2 ttl=113 time=1.24 ms
64 bytes from 2001:4860:4860::8888: icmp_seq=3 ttl=113 time=1.25 ms
64 bytes from 2001:4860:4860::8888: icmp_seq=4 ttl=113 time=1.25 ms                                                                                                    
64 bytes from 2001:4860:4860::8888: icmp_seq=5 ttl=113 time=1.25 ms

If any of the pings aren't working make sure to check if the firewall is blocking and you have ipv6 forwarding enabled on host.

Tested on

See also

References