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         UG    0      0        0 enp8s0
default         UG    1024   0        0 eno1      *        U     0      0        0 eno1      *      UH    1024   0        0 eno1

In order to delete the gateway, I run this:

route del default gw

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.

Description=delete gateways from the main routing table

ExecStart=/bin/route -b /etc/iproute2/delgw


file delgw:

del default gw
  • 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 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.