5

I would like to have a network for 10+ Pi with a switch (192.168.42.x). This switch is connected to Internet via one port (to an another switch).

I try to have one Pi with the ip (eth0) 192.168.1.127 (which is connected to internet) and a virtual ip like 192.168.42.1 to connect to the other Pi (and they will have Internet via Pi #1)

So far, no luck :)

My dhcpcd.conf :

denyinterfaces eth0

interface eth0.2
static ip_address=192.168.42.1/24
static routers=192.168.42.1
static domain_name_server=1.1.1.1 8.8.8.8

And i add in /etc/network/interfaces

auto eth0.2
iface eth0.2 inet manual
vlan-raw-device eth0

I've installed vlan (apt-get install vlan) et /etc/modules contains 8021q.

The interface eth0.2 is displayed when i do a 'ifconfig' but i cannot ping an another pi on the switch (for example with the ip 192.168.42.3).

My ifconfig :

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.1.127  netmask 255.255.255.0  broadcast 192.168.1.255
    ether b8:27:eb:4d:36:17  txqueuelen 1000  (Ethernet)
    RX packets 2201  bytes 162493 (158.6 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 983  bytes 73130 (71.4 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0.2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.42.1  netmask 255.255.255.0  broadcast 192.168.42.255
    inet6 fe80::55c4:a14b:2dec:f810  prefixlen 64  scopeid 0x20<link>
    ether b8:27:eb:4d:36:17  txqueuelen 1000  (Ethernet)
    RX packets 0  bytes 0 (0.0 B)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 135  bytes 8414 (8.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 1000  (Boucle locale)
    RX packets 130  bytes 7259 (7.0 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 130  bytes 7259 (7.0 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 10.3.141.1  netmask 255.255.255.0  broadcast 10.3.141.255
    inet6 fe80::baf7:cd15:76c2:e46a  prefixlen 64  scopeid 0x20<link>
    ether b8:27:eb:18:63:42  txqueuelen 1000  (Ethernet)
    RX packets 603  bytes 91522 (89.3 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 147  bytes 24893 (24.3 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

My routing table is :

default         livebox         0.0.0.0         UG    202    0        0 eth0
default         192.168.42.1    0.0.0.0         UG    204    0        0 eth0.2
default         10.3.141.1      0.0.0.0         UG    303    0        0 wlan0
10.3.141.0      0.0.0.0         255.255.255.0   U     303    0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0
192.168.42.0    0.0.0.0         255.255.255.0   U     204    0        0 eth0.2

Perhaps, there is too much default route ? What have I missed ?

Thanks in advance ! :)

2
  • "there is too much default route ?" -> Yes, you should not really have more than one; the metric (5th column, 202, 204, etc) will end up deciding between them. I think it ends up configured this way because it is assumed two of the interfaces are fallbacks, i.e., meant to replace higher priority ones when they go down. See: unix.stackexchange.com/a/345979/25985 Obviously this isn't your scenario, so you probably have to manual configure the routes.
    – goldilocks
    Commented Jun 27, 2018 at 17:08
  • I'll try to edit the route to have only one default route. Thanks :)
    – Kheops66
    Commented Jun 28, 2018 at 7:46

2 Answers 2

2

From your description I understand this network setup:

                                    managed switch
                            +----------------------------+
     vlan1                  |                            |
rpi1 <--------- trunk ----->| port1 - tagged             |
     vlan42                 |                            |
                            |                            |
rpi2 <--------------------->| port2 - untagged (PVID 42) |
                            |                            |
                            |                            |
Internet <----------------->| port3 - untagged (PVID 1)  |
                            |                            |
                            +----------------------------*

An interface cannot be connected to two subnets, except with vlans. You tried this with an additional ip address on the interface. A second ip address can only be set from the same subnet the interface is connected to, in your case either from 192.168.1.0/24 or from 192.168.42.0/24. If you want to use two vlans on one wire (raw device eth0) then your switch must support it.

To define the two vlans you have to add something like this in /etc/network/interfaces:

iface vlan1 inet static
    vlan-raw-device eth0
    address 192.168.1.127
    netmask 255.255.255.0
    gateway 192.168.1.1

iface vlan42 inet static
    vlan-raw-device eth0
    address 192.168.42.1
    netmask 255.255.255.0
    gateway 192.168.42.254

If your switch does not support vlans then forget it. A possible solution then is to buy a second usb ethernet dongle to get two different real interfaces.

3
  • I've forgotten that the switch have to support vlans. It's a small one, it is not manageable. I'll try your solution with 2 ethernet interface. Thanks !
    – Kheops66
    Commented Jun 28, 2018 at 7:45
  • @Kheops66 is my answer acceptable? I have spent some time for it.
    – Ingo
    Commented Jun 28, 2018 at 9:20
  • First time on stackexchange, sorry I just saw the accept button :)
    – Kheops66
    Commented Jun 28, 2018 at 9:36
0

If you don't need a real vlan you can assign additional addresses like this with colon instead of dot. This way you simply have multiple addresses with one interface regardless if the main interface is configured via DHCP or not. You should be able to ping each address easily without any router involved. Please read here for further instructions: Multiple IP addresses on one Interface

/etc/network/interfaces

auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
    address 192.168.1.43
    netmask 255.255.255.0
2
  • If you don't need a real vlan you can do everything. You can also use a DHCP server. Using multiple ip addresses on one interface has nothing to do with different networks. All ip addresses are on the same network. There is no separation.
    – Ingo
    Commented Jan 20, 2019 at 22:17
  • You have logical different networks for sure. Of course it is the same physical one then and there is absolutely no security separation involved.
    – Thomas
    Commented Jan 21, 2019 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.