Score:0

How to configure new (DHCP configured) interface with non system default route using systemd/networkd?

jp flag

I am trying to configure Linux system, so during boot/adding new modem (visible as usb0 interface ) any software binding to modem interface (usb0) IP# will use offered by modem GW/routing instead of system default routing/GW. I am trying to use systemd/networkd, but as far without success :( below what I try:

Having /etc/systemd/network/usb0.network [1] which should configure interface with DHCP, set GW and default on routing table 101 aka via_usb0.

Having plugged modem [2] I see IP# assigned for usb0 [3], policy routing table updated with iif usb0/oif usb0 entries [4] and via_usb0 routing table created [5].

Q1: Why I am unable to ping usb0 GW now?

# ping 192.168.42.129 
ping: connect: Network is unreachable

Route to 192.168.42.129 should be taken from local table [6], right ?

Q2: Why pinging usb0 GW explicitly via usb0 fails with martian packets recorded in kernel log [7] , though I can see them going back and forth on usb0 interface [8]?

# ping 192.168.42.129 -I usb0
PING 192.168.42.129 (192.168.42.129) from 192.168.42.20 usb0: 56(84) bytes of data.
^C
--- 192.168.42.129 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1016ms

Q3: Why adding explicit ip rule on usb0 source IP# helps with problem from Q2? After

ip rule add from 192.168.42.20 pref 103  table via_usb0

I get ping reply (and no martians logged):

# ping 192.168.42.129 -I usb0
PING 192.168.42.129 (192.168.42.129) from 192.168.42.20 usb0: 56(84) bytes of data.
64 bytes from 192.168.42.129: icmp_seq=1 ttl=64 time=0.674 ms

Should not iif/oif rules

101:    from all iif usb0 lookup via_usb0
102:    from all oif usb0 lookup via_usb0

be enough to use via_usb0 routing tale?

Q4: Is there any other working way to achieve my goal?

Thanks in advance for any input.

[1]:

[Match]
Name=usb0

[Network]
IPForward=yes
DHCP=ipv4
DNSDefaultRoute=false


[DHCPv4] 
UseRoutes=true
RouteTable=101
UseGateway=true
UseDNS=false
UseNTP=false
UseSIP=false
UseHostname=false
UseDomains=false
UseTimezone=false

[RoutingPolicyRule]
Family = ipv4
IncomingInterface=usb0
Table = 101
Priority = 101

[RoutingPolicyRule]
Family = ipv4
OutgoingInterface=usb0
Table = 101
Priority = 102

[2]:

kernel: usb 1-1: new high-speed USB device number 6 using xhci_hcd
kernel: usb 1-1: New USB device found, idVendor=04e8, idProduct=6860, bcdDevice= 4.00
kernel: usb 1-1: New USB device strings: Mfr=2, Product=3, SerialNumber=4
kernel: usb 1-1: Product: SAMSUNG_Android
kernel: usb 1-1: Manufacturer: SAMSUNG
kernel: usb 1-1: SerialNumber: 42000352b6245200
kernel: cdc_acm 1-1:1.1: ttyACM0: USB ACM device
networkd-dispatcher[1068]: WARNING:Unknown index 6 seen, reloading interface list
systemd-udevd[13537]: Using default interface naming scheme 'v245'.
systemd-udevd[13537]: ethtool: autonegotiation is unset or enabled, the speed and duplex are not writable.
systemd-networkd[13409]: usb0: Link UP
systemd-networkd[13409]: usb0: Gained carrier

[3]:

6: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
    link/ether 5a:a3:60:fd:ed:4a brd ff:ff:ff:ff:ff:ff
    inet 192.168.42.20/24 brd 192.168.42.255 scope global dynamic noprefixroute usb0
       valid_lft 3491sec preferred_lft 3491sec

[4]:

# ip rule show
0:      from all lookup local
101:    from all iif usb0 lookup via_usb0
102:    from all oif usb0 lookup via_usb0
32766:  from all lookup main
32767:  from all lookup default

[5]:

# ip route show table via_usb0
default via 192.168.42.129 dev usb0 proto dhcp src 192.168.42.20 metric 1024 
192.168.42.0/24 dev usb0 proto dhcp scope link src 192.168.42.20 
192.168.42.129 dev usb0 proto dhcp scope link src 192.168.42.20 metric 1024

[6]:

# ip route show table local
broadcast 10.41.0.0 dev tinc_korns proto kernel scope link src 10.41.1.2 
local 10.41.1.2 dev tinc_korns proto kernel scope host src 10.41.1.2 
broadcast 10.41.255.255 dev tinc_korns proto kernel scope link src 10.41.1.2 
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.42.0 dev usb0 proto kernel scope link src 192.168.42.20 
local 192.168.42.20 dev usb0 proto kernel scope host src 192.168.42.20 
broadcast 192.168.42.255 dev usb0 proto kernel scope link src 192.168.42.20

[7]:

kernel: IPv4: martian source 192.168.42.20 from 192.168.42.129, on dev usb0

[8]:

# tcpdump -i usb0 -n
10:44:08.361514 IP 192.168.42.20 > 192.168.42.129: ICMP echo request, id 4, seq 1, length 64
10:44:08.362095 IP 192.168.42.129 > 192.168.42.20: ICMP echo reply, id 4, seq 1, length 64

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.