1

I'm following an answer I found on Serverfault located here https://serverfault.com/a/487911/141509

I created the following routing table in rt_table

10 wlx74da388c32c7

Below is my full rt_table

#
# reserved values
#
255 local
254 main
253 default
0   unspec
#
# local
#
#1  inr.ruhep
10 wlx74da388c32c7

I'm trying to convert my ip route add and ip rule add commands to my netplan. Below are the two commands.

ip route add default via 172.16.11.254 table wlx74da388c32c7
ip rule add from 172.16.11.107 lookup wlx74da388c32c7

172.16.11.107 is the ip address and 172.16.11.254 is the gateway address. Below is what I have now, but I do know that it's wrong

network:
    ethernets:
        enp1s0:
            addresses:
            - 192.168.1.212/24
            gateway4: 192.168.1.1
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                search: []
            optional: true
    wifis:
        wlx74da388c32c7:
            dhcp4: true
            access-points:
                "home":
                    password: "mypassword"
            routes:
                - to: 172.16.11.0/24
                  via: 172.16.11.254
                  table: 10
            routing-policy:
                - from: 172.16.11.0/24
                  table: 10
    version: 2

EDIT

Below is my latest yaml file

network:
    ethernets:
        enp1s0:
            addresses:
            - 192.168.1.212/24
            gateway4: 192.168.1.1
            nameservers:
                addresses:
                - 8.8.8.8
                - 8.8.4.4
                search: []
            optional: true
    wifis:
        wlx74da388c32c7:
            dhcp4: true
            access-points:
                "home":
                    password: "mypassword"
            routes:
                - to: 0.0.0.0/0
                  via: 172.16.11.254
                  metric: 100
                  table: 10
            routing-policy:
                - from: 172.16.11.0/24
                  table: 10
    version: 2

and below is ip addr show command

root@poweredge:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:1e:4f:cd:c1:5f brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.212/24 brd 192.168.1.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::21e:4fff:fecd:c15f/64 scope link 
       valid_lft forever preferred_lft forever
3: wlx74da388c32d0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 74:da:38:8c:32:d0 brd ff:ff:ff:ff:ff:ff
4: wlx74da388c32c7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 74:da:38:8c:32:c7 brd ff:ff:ff:ff:ff:ff
    inet 172.16.11.107/24 brd 172.16.11.255 scope global dynamic wlx74da388c32c7
       valid_lft 2997sec preferred_lft 2997sec
    inet6 fe80::76da:38ff:fe8c:32c7/64 scope link 
       valid_lft forever preferred_lft forever

ip rule show result

root@poweredge:~# ip rule show
0:  from all lookup local 
0:  from 172.16.11.0/24 lookup 10 
32766:  from all lookup main 
32767:  from all lookup default 

ip route show result

root@poweredge:~# ip route show
default via 192.168.1.1 dev enp1s0 proto static 
default via 172.16.11.254 dev wlx74da388c32c7 proto dhcp src 172.16.11.107 metric 600 
172.16.11.0/24 dev wlx74da388c32c7 proto kernel scope link src 172.16.11.107 
172.16.11.254 dev wlx74da388c32c7 proto dhcp scope link src 172.16.11.107 metric 600 
192.168.1.0/24 dev enp1s0 proto kernel scope link src 192.168.1.212 
Arya
  • 121
  • 1
  • 6
  • wlx74da388c32c7 is a iproute2 table name not interface name I think. Tables name for iproute2 you can find in this file: `cat /etc/iproute2/rt_tables` and the number which represent it. This number you should use wit 'table:' parameter. – mariaczi Jun 20 '18 at 08:05
  • wlx74da etc. is likely the correct name for a USB wireless interface. @mariaczi – chili555 Jun 20 '18 at 10:47
  • @chili555 And when USB wifi card is plugged-in iproute2 package automatically create new tables for it (based on both commands provided by author of this subject)? As I know, the tables must be created manually by editing the file mentioned in my earlier comment. – mariaczi Jun 20 '18 at 10:54
  • @mariaczi I have edited my question, I had left some info out which I added now. I did modify rt_table – Arya Jun 20 '18 at 17:17
  • @chili555 I modified the question and added my modified rt_table – Arya Jun 20 '18 at 17:18
  • wlx74da388c32c7 is both the interface name and the table name in rt_table – Arya Jun 20 '18 at 17:19

2 Answers2

1

Why didn’t you look at my wiki?

And to be helpful you need to show the ip rules and ip routes content ... we don’t care about rt_table or any content of files besides your config file. If tools are using yaml is specifically to not having the need to look into system files afterwards.

And what are you supposed to want to do with this :

routes: - to: 172.16.11.0/24 via: 172.16.11.254 table: 10

Only access the subnetwork 172.16.11.0? Because if it is just that then you don’t need a gateway, if the equipment is directly connected then it will answer to all request by default coming from this subnet. That’s networking 101 and basically the difference between ‘Connected’ and ´Static’ . If the goal is to have a real gateway then your route is for sure not good and should be 0.0.0.0/0 which is the network and netmask that means all networks from everywhere. Again networking 101. Is it clearer like that ?

vigilian
  • 814
  • 2
  • 7
  • 14
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackexchange.com/rooms/79310/discussion-on-answer-by-vigilian-convert-ip-route-add-to-netplan). – Thomas Ward Jun 25 '18 at 02:02
0

Try setting on-link attribute to true in routes:

routes:
 - to: 0.0.0.0/0
   via: 172.16.11.254
   on-link: true
   metric: 100
   table: 10
damadam
  • 2,815
  • 3
  • 17
  • 38