3

I would like to configure an embedded device to behave as a wireless router, and I would like to achieve it preferably using networkd configuration files.

I have two *.network files, a wired WAN interface and a wireless LAN interface, and I would like LAN traffic to be able to access WAN.

# cat /etc/systemd/network/wired.network 
[Match]
Name=eth0

[Network]
DHCP=ipv4
IPForward=yes
IPMasquerade=yes

As is common for wireless routers, the wireless LAN network anso provides DHCP. I used the systemd integrated DHCP server.

# cat /etc/systemd/network/wireless.network
[Match]
Name=wlan0*

[Network]
Description = Wireless IP interface
DHCPServer= yes

[Address]
Address   = 192.168.128.1/24
Broadcast = 192.168.128.255

[DHCPServer]
PoolOffset          = 10
PoolSize            = 40
EmitDNS             = yes
DNS                 = 8.8.8.8, 8.8.4.4
DefaultLeaseTimeSec = 600
MaxLeaseTimeSec     = 7200

[Route]

I assume there should be a NAT between the two networks, as is common for wireless routers, but it is not an explicit requirement.

This is as far as I got with my current knowledge, the wired interface connects to WAN properly, and the wireless access point also provides DHCP addresses. But I am unable to access WAN (internet) if I connect to the WiFi AP.

Here is some network interface status:

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    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 pfifo_fast state UP group default qlen 1000
    link/ether 00:26:32:f0:03:21 brd ff:ff:ff:ff:ff:ff
    inet 192.168.178.107/24 brd 192.168.178.255 scope global dynamic eth0
       valid_lft 4650sec preferred_lft 4650sec
    inet6 fe80::226:32ff:fef0:321/64 scope link
       valid_lft forever preferred_lft forever
3: sit0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default
    link/sit 0.0.0.0 brd 0.0.0.0
4: wlan0wext: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:1d:43:40:0d:04 brd ff:ff:ff:ff:ff:ff
    inet 192.168.128.1/24 brd 192.168.128.255 scope global wlan0wext
       valid_lft forever preferred_lft forever
    inet6 fe80::21d:43ff:fe40:d04/64 scope link
       valid_lft forever preferred_lft forever

And route status:

# ip route
default via 192.168.178.1 dev eth0  proto dhcp  src 192.168.178.107  metric 1024
192.168.128.0/24 dev wlan0wext  proto kernel  scope link  src 192.168.128.1
192.168.178.0/24 dev eth0  proto kernel  scope link  src 192.168.178.107
192.168.178.1 dev eth0  proto dhcp  scope link  src 192.168.178.107  metric 1024

# ip route show table local
broadcast 127.0.0.0 dev lo  proto kernel  scope link  src 127.0.0.1
local 127.0.0.0/8 dev lo  proto kernel  scope host  src 127.0.0.1
local 127.0.0.1 dev lo  proto kernel  scope host  src 127.0.0.1
broadcast 127.255.255.255 dev lo  proto kernel  scope link  src 127.0.0.1
broadcast 192.168.128.0 dev wlan0wext  proto kernel  scope link  src 192.168.128.1
local 192.168.128.1 dev wlan0wext  proto kernel  scope host  src 192.168.128.1
broadcast 192.168.128.255 dev wlan0wext  proto kernel  scope link  src 192.168.128.1
broadcast 192.168.178.0 dev eth0  proto kernel  scope link  src 192.168.178.107
local 192.168.178.107 dev eth0  proto kernel  scope host  src 192.168.178.107
broadcast 192.168.178.255 dev eth0  proto kernel  scope link  src 192.168.178.107

I was not able to find many examples for the [Route] section, and I only have the basic understanding of routing.

Regards, Iztok Jeras

0

For RHEL 5 & 6 considering 153.xx is your System IP

Temporary route add

ip route add 192.168.10.0/24 via 153.254.92.42 dev eth0

Permanent route Add

echo "192.168.10.0/24 via 153.254.92.XX" >> /etc/sysconfig/network-scripts/route-eth1

For RHEL 7

Temporary route add

ip route add 192.168.20.0/29 via 153.254.92.XX dev enp00s0f0

Permanent route Add

echo "192.168.10.0/24 via 153.254.92.XX" >> /etc/sysconfig/network-scripts/ifcfg-enp00s0f0
0

I found with the above .network files that masquerading was missing. The following fixes that:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

It appeared that my version of systemd was built without iptables support. Building it again with option 'libiptc' fixes that. I needed to add

IPForward=yes
IPMasquerade=yes

to the wireless.network file as well.

-2

The issue was not with the route configuration, instead iptables configuration was missing.

  • 1
    Would you mind sharing what iptables configuration you were missing? As it stands, this is not terribly helpful. Perhaps you could provide an explanation. Thanks. – Jonathan Komar Mar 17 '17 at 7:50

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.