I have some route add commands to run on Ubuntu. It works when I copy the command and paste it on the terminal. But I've tried to create a bash script which looks something like this


sudo route add -net 'someIp' netmask gw 'anotherIp' 
sudo route add -net 'someOtherIp' netmask gw 'anotherIp'

But when I run it. the output is:

SIOCADDRT: Dispositivo inexistente

which can be translated to SIOCADDRT: device does not exist

I've run chmod +x on the file and tried running the script with sudo but it did not work.

What am I missing?

  • Can you please make sure that you are not trying to add an already existent route. SIOCADDRT: device does not exist SIOC: Serial Input Output Controller. ADD: ADD (addition). RT: RouTe (routing ip). File exists – Routing is already configured so delete wrong one and add the new one.
    Jan 23, 2020 at 12:00
  • That is probably the issue, because when I copy the commands and paste it, sometimes a warning shows up. But I still don't get why it does not add the missing routes when the script is running but it does get added when I copy the same commands and paste it on the terminal. Do you know why this happens? Jan 23, 2020 at 14:50
  • can you add the interface name after the command in the script and test it, please? EXAMPLE: sudo route add -net 'someIp' netmask gw 'anotherIp' eth0
    Jan 23, 2020 at 17:06
  • It outputs the same result as before Jan 23, 2020 at 17:25
  • did you remove the already created rules before executing the script? Also, the rules that are being add shouldn´t overlap existing ones.
    Jan 23, 2020 at 17:30

1 Answer 1


After a few days, I finally found the problem. At first, I hadn't added the #!/bin/bash to the script, but after I added it, it was still not working. Then I found this post(in Portuguese) explaining that the problem could be some invisible characters on the file, which makes sense because I had converted it from a .bat file manually. So I just had to run sed -i 's/\r$//' routes.sh and everything started working.

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.