Wednesday 8 May 2019

multiple ipv4 and ipv6 addresses in /etc/network/interfaces on Raspberry Pi

I have been very frustrated trying to set up multiple ipv4 and ipv6 address on one interface, in this instance, eth0.

alan@strigosus ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:cb:6c:98 
          inet addr:90.155.48.158  Bcast:90.155.48.159  Mask:255.255.255.224
          inet6 addr: 2001:8b0:7c:1::136/64 Scope:Global
          inet6 addr: 2001:8b0:7c:1::158/64 Scope:Global
          inet6 addr: fe80::ba27:ebff:fecb:6c98/64 Scope:Link
          inet6 addr: 2001:8b0:7c:1::45/64 Scope:Global
          inet6 addr: 2001:8b0:7c:1::44/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:48007 errors:0 dropped:0 overruns:0 frame:0
          TX packets:70787 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:9720366 (9.2 MiB)  TX bytes:16787070 (16.0 MiB)

eth0:1    Link encap:Ethernet  HWaddr b8:27:eb:cb:6c:98 
          inet addr:81.187.211.44  Bcast:81.187.211.47  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:2    Link encap:Ethernet  HWaddr b8:27:eb:cb:6c:98 
          inet addr:81.187.211.45  Bcast:81.187.211.47  Mask:255.255.255.240
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:3    Link encap:Ethernet  HWaddr b8:27:eb:cb:6c:98 
          inet addr:90.155.48.136  Bcast:90.155.48.159  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:4    Link encap:Ethernet  HWaddr b8:27:eb:cb:6c:98 
          inet addr:90.155.48.134  Bcast:90.155.48.159  Mask:255.255.255.224
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:4687 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4687 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:677569 (661.6 KiB)  TX bytes:677569 (661.6 KiB)



The solution I found to work was to have one alias for each ip

This is my /etc/network/interfaces


auto lo eth0  eth0:1 eth0:2 eth0:3 eth0:4 eth0:5 eth0:6 eth0:7 eth0:8

iface lo inet loopback

# strigosus
# Pi Also for dhcp
iface eth0 inet static
address 90.155.48.158
netmask 255.255.255.224
gateway 90.155.48.129


# idaeus
# Pi
iface eth0:1 inet static
address 81.187.211.44
netmask 255.255.255.240
gateway 81.187.211.33


# ns-rosifolius
# for dns
iface eth0:2 inet static
address 81.187.211.45
netmask 255.255.255.240
gateway 81.187.211.33


# ns-sieboldii
# for dns
iface eth0:3 inet static
address 90.155.48.136
netmask 255.255.255.224
gateway 90.155.48.129


# ellipticus
# Pi. For sshd port 80
iface eth0:4 inet static
address 90.155.48.134
netmask 255.255.255.224
gateway 90.155.48.129


# strigosus
# Pi.
iface eth0:5 inet6 static
address 2001:8b0:7c:1::158/64
gateway 2001:8b0:7c:1:1e74:dff:fe51:4749


# idaeus
# Pi
iface eth0:6 inet6 static
address 2001:8b0:7c:1::44/64
gateway 2001:8b0:7c:1:1e74:dff:fe51:4749


# ns-rosifolius
# for dns
iface eth0:7 inet6 static
address 2001:8b0:7c:1::45/64
gateway 2001:8b0:7c:1:1e74:dff:fe51:4749
# gateway 2001:8b0:7c:1:1e74:dff:fe51:4749
# # netmask 64


# ns-sieboldii
# for dns
iface eth0:8 inet6 static
address 2001:8b0:7c:1::136/64
gateway 2001:8b0:7c:1:1e74:dff:fe51:4749


This also worked on my new Pi with Raspian Stretch after disabling dhcpcd.  I wanted to do this as the new Pi is to be my new everything server.