rtr7 / router7

router7 is a small home internet router completely written in Go. It is implemented as a gokrazy appliance.
https://router7.org
Apache License 2.0
2.69k stars 110 forks source link

How to configure multiple LAN interfaces? #84

Closed muja closed 8 months ago

muja commented 8 months ago

I'm trying to get multiple interfaces working. for this I've provided the interfaces in /perm/interfaces.json:

{
    "interfaces": [
        {
            "hardware_addr": "...",
            "name": "uplink0"
        },
        {
            "hardware_addr": "...",
            "name": "lan0",
            "addr": "10.0.0.1/25"
        },
        {
            "hardware_addr": "...",
            "name": "lan1",
            "addr": "10.0.0.128/29"
        },
        {
            "hardware_addr": "...",
            "name": "lan2",
            "addr": "10.0.0.136/29"
        }
    ]
}

However, dhcp4d only listens on lan0 so I can't get dynamic IPs on the other ports. Obviously this could be fixed inside dhcp4d which would be awesome but my idea was to simply have a dhcp process running per port, supervised by gokrazy, configure the lease path and the HTTP server. However, running multiple processes of the same instance with gokrazy doesn't seem possible, right? What would you suggest in my case?

muja commented 8 months ago

I just noticed even with DHCP working / clients getting IPs, there is no internet access. I believe the nftables is missing? I'm kinda new to networking/routing -- where would I need to change things to make my setup work?

stapelberg commented 8 months ago

My general recommendation for the scenario where you have multiple LAN ports is to bridge them together to one interface:

{
    "bridges":[
    {
        "name": "lan0",
        "interface_hardware_addrs": [
        "64:9d:99:b1:fa:63",
        "b8:ce:f6:2f:bf:93",
        "a8:a1:59:3a:cc:53"
        ]
    }
    ],
    "interfaces": [
    {
        "hardware_addr": "b8:ce:f6:2f:aa:93",
        "fec": "RS",
        "name": "uplink0"
    },
    {
        "name": "lan0",
        "addr": "10.0.0.1/24"
    }
    ]
}
muja commented 8 months ago

Thanks, yes that solved it. Out of curiosity, why didn't the devices on the other ports have network/internet access even when I assigned static IP addresses to them?

And what does the "fec": "RS" do?

stapelberg commented 8 months ago

Out of curiosity, why didn't the devices on the other ports have network/internet access even when I assigned static IP addresses to them?

Because the networking configuration, specifically the nftables rules, only configure NAT between lan0 and uplink0, no other interfaces: https://github.com/rtr7/router7/blob/95fc74327defd019c54ef4e8f73f21a584ffee3e/internal/netconfig/netconfig.go#L841-L850

And what does the "fec": "RS" do?

Google “fec RS” :) It’s forward error correction, which is needed for some SFP interfaces to work.