2

There are two physical interfaces on my machine, both with DHCP, so my default routing table looks like this:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.10.26.129    0.0.0.0         UG    0      0        0 enp8s0
default         10.10.24.1      0.0.0.0         UG    1024   0        0 eno1
10.10.24.0      *               255.255.255.0   U     0      0        0 eno1
10.10.24.1      *               255.255.255.255 UH    1024   0        0 eno1

In order to delete the 10.10.24.1 gateway, I run this:

route del default gw 10.10.24.1

I want it to be deleted after booting, systemd would be the suitable way, but how should I delete gateway from default routing table use systemd? Below is what I tried, but doesn't work.

[Unit]
Description=delete gateways from the main routing table

[Service]
Type=idle
RemainAfterExit=yes
ExecStart=/bin/route -b /etc/iproute2/delgw

[Install]
WantedBy=network.target

file delgw:

del default gw 10.10.24.1
  • I think you've got the right idea, and are just missing syntax. My route doesn't accept a -b option, nor mention any option to read from a file. Try ignoring the delgw file and just calling /bin/route del default gw 10.10.24.1 from the service file. – Tom Hunt Oct 22 '15 at 15:04
  • I think that it could be possible that when you execute the command to delete the entry, this entry is not in the table yet – migrc Oct 22 '15 at 15:07
  • @TomHunt Tried, still doesn't work, that -b is just to make the files organized. – Zhenxiao Hao Oct 22 '15 at 15:10
  • @migrc After booting, I run systemctl start myservice.service, my routing table stays the same, but in this case, the entry is already in the entry. – Zhenxiao Hao Oct 22 '15 at 15:13
  • Why don't you send the output of the command to a log file to see what is happening? – migrc Oct 22 '15 at 15:14

Your Answer

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

Browse other questions tagged or ask your own question.