1

I am trying to configure the wifi and ethernet ports on a linux box in a non-standard way. I have never touched this kind of stuff before, so please excuse my naivety. I have basically just YOLO'd my way into the documentation head first and have made it pretty far and got it to work. But there is still some oddities and I don't fully understand why it works. So if I could, I would like to describe this fully, then anyone more knowledge please correct me and explain where I did something wrong.

I have a mini pc that has 2 ethernet ports and 1 wifi. I am trying to configure it so that internet comes in on one ethernet port, then is broadcast out on both WIFI and the other ethernet port. Basically configuring it to work like a wifi router.

So.

Here is my /etc/netplan/01-network-manager-all.yaml

network:
    version: 2
    renderer: networkd
    ethernets:
        enp0s31f6:
            dhcp4: true
        enp1s0:
            addresses:
            - 192.168.2.1/24
            dhcp4: false
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                search: []
        wlp2s0:
            addresses:
            - 10.42.0.1/24
            dhcp4: false
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                search: []
    bridges:
        br0:
            interfaces: [enp0s31f6, enp1s0, wlp2s0]
            dhcp4: true
            addresses:
            - 100.80.0.1/24
            parameters:
                stp: false
                forward-delay: 0

Here is my /etc/default/dhcpd.conf

INTERFACES="enp1s0 wlp2s0"

Here is my /etc/dhcp/dhcpd.conf

option domain-name "whatever.you.want";
option domain-name-servers 8.8.8.8, 8.8.4.4;
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;
authoritative;
log-facility local7;
subnet 10.42.0.1 netmask 255.255.255.0 {
     range 10.42.0.101 10.42.0.200;
     option subnet-mask 255.255.255.0;
     option routers 10.42.0.1;
     option broadcast-address 10.42.0.255;
}
subnet 100.80.0.1 netmask 255.255.255.0 {
     range 100.80.0.101 100.80.0.200;
     option subnet-mask 255.255.255.0;
     option routers 100.80.0.1;
     option broadcast-address 100.80.0.255;
}
subnet 192.168.2.1 netmask 255.255.255.0 {
     range 192.168.2.101 192.168.2.200;
     option subnet-mask 255.255.255.0;
     option routers 192.168.2.1;
     option broadcast-address 192.168.2.255;
}

I have run all the correct commands (I think)

sudo netplan --debug generate
sudo netplan apply
sudo systemctl restart isc-dhcp-server
sudo systemctl enable isc-dhcp-server
sudo systemctl status isc-dhcp-server

So this works. However I know I probably did something wrong. It also has quirks. Randomly seemed to break a few times with an error popping up that said nothing. Also when I try to plug it into a certain 4G hotspot it just does not work, however that 4G hotspot successfully delivers internet to other devices, it also receives internet just fine from other ethernet sources.

So is this configured correctly? How would I change these files to configure it correctly?

Also for good measure my ifconfig

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 100.80.0.1  netmask 255.255.255.0  broadcast 100.80.0.255
        inet6 fe80::14a8:83ff:fe5b:a89c  prefixlen 64  scopeid 0x20<link>
        ether 16:a8:83:5b:a8:9c  txqueuelen 1000  (Ethernet)
        RX packets 666051  bytes 252795968 (252.7 MB)
        RX errors 0  dropped 59  overruns 0  frame 0
        TX packets 127129  bytes 14963222 (14.9 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s31f6: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 00:01:2e:84:6a:13  txqueuelen 1000  (Ethernet)
        RX packets 691307  bytes 261567317 (261.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 242102  bytes 38886894 (38.8 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xdf300000-df320000  

enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.1  netmask 255.255.255.0  broadcast 192.168.2.255
        ether 00:01:2e:84:6a:14  txqueuelen 1000  (Ethernet)
        RX packets 111556  bytes 21621626 (21.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 523333  bytes 80568249 (80.5 MB)
        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  (Local Loopback)
        RX packets 11909999  bytes 4519986237 (4.5 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11909999  bytes 4519986237 (4.5 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.42.0.1  netmask 255.255.255.0  broadcast 10.42.0.255
        ether 00:24:d6:fc:f5:e9  txqueuelen 1000  (Ethernet)
        RX packets 87180  bytes 10348796 (10.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 134948  bytes 148087795 (148.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • So you want to have other devices access the internet through this device? – datUser Feb 26 at 1:28
  • Yes. I want other devices to be able to access internet through wlp2s0 (wifi) and ep1s0 (ethernet), while the internet comes in through enp0s31f6 (ethernet). Configure it to work like a wireless router. – rygo6 Feb 26 at 17:09
  • Ok, then iptables is your friend. You must define the routing rules yourself, this is not default behavior of any network configuration I am aware of. – datUser Feb 26 at 19:06
1

To have your device function as a router (technically a default gateway for other devices to use to access the internet or another network) you will need the following configuration settings:

  1. Have the devices that want to access the internet through your router device set to use that device as a default gateway. If they are getting DHCP from this device, this could be passed in as a DHCP option. Otherwise you need to add this route on the devices themselves. Check their routing tables with the ip command:

    $ ip route show
    default via 172.31.100.1 dev eno2 proto static
    ...
    

    You should see the address of your router host as their default gateway route.

  2. Enable forwarding on your router host:

    $ echo 0 > /proc/sys/net/ipv4/ip_forward
    
  3. Set up routing from eth0 to eth1 where eth0 is our 'LAN' adapter and eth1 is our 'WAN' adapter:

    iptables -t nat -I POSTROUTING -o eth1 -j MASQUERADE
    iptables -I FORWARD -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -I FORWARD -i eth1  -j ACCEPT
    
  4. Test.

  5. To remove these settings:

    iptables -t nat -D POSTROUTING -o eth1 -j MASQUERADE
    iptables -D FORWARD -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
    iptables -D FORWARD -i eth1  -j ACCEPT
    echo 1 > /proc/sys/net/ipv4/ip_forward
    

All of these commands will need to be run as the super user.

  • So do I even need any of the Netplan or dhcpd.conf file stuff? Can I just remove that all that? Should I set my netplan renderer back to being the NetworkManager? – rygo6 Feb 26 at 20:10
  • I ran these commands but I don't think it made any difference. The system is already technically working via the configs I initially posted, they just seem to have odd quirks, like one of my 4G hotspots when plugged in via ethernet doesn't deliver internet, but the hotspot is functioning just fine. Also via the config I initially posted my wifi lan has it's own IP range, my ethernet lan has it's own IP range, and the bridge also has it's own IP range. I assume thats wrong? I thought you could just give the bridge an IP range, but I couldn't get that to work. – rygo6 Feb 26 at 20:19
  • Bridging is not routing. Bridging is a layer 2 abstraction, you are looking for layer 3 functionality. I would remove your bridge interface (it's using a public IP address anyway - not a good idea) and set up the routing as I illustrated above on one pair of interfaces and get that working. Then add the second lan interface. – datUser Feb 26 at 20:46
  • Ok I think I actually go it work all correctly with iptables and deleted the bridge. Thanks for that. One other thing I am curious about is, whats the proper way to configure wifi to be an access point in this setup? I have pulled that off I think in a hacky way where I just turned on wifi access point through network manager UI, then I set the wifi wlp2s0 to be ethernet in netplan. But weirdly I disabled networkmanager as the netplan renderer so I dont understand how that is working. – rygo6 Feb 27 at 17:27
  • Perhaps that would be a good question to post. The answer is a bit long for comments. – datUser Feb 27 at 19:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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