I'm trying to configure the network interface on embedded linux using ifconfig:

ifconfig eth0 192.168.0.101 netmask 255.255.255.0

but I don't know how to add the default gateway as an ifconfig parameter,

Any Ideas?

  • Please specify which embedded Linux you are using. – Rui F Ribeiro Feb 1 '16 at 11:24
up vote 16 down vote accepted

ifconfig is not the correct command to do that.

You can use route like in route add default gw 192.168.0.254 for example.

And if route is not present, but ip is, you can use it like this: ip route add default via 192.168.0.254 dev eth0, assuming that 192.168.0.254 is the ip of your gateway

  • ip should be the first choice.ip r add default via [gw]. – prosti Sep 24 at 12:02

ifconfig is deprecated on Linux and furthermore, it's the wrong tool for the job. To set the default gateway on Linux use the ip command as follows:

ip route add default via <host> dev <dev>

# e.g.
ip route add default via 192.168.0.101 dev eth0

Using route

route add default gw {IP-ADDRESS} {INTERFACE-NAME}

example: route add default gw 192.168.1.2 eth0

OR use hostname such as dsl-router:

route add default gw dsl-router eth0 

Or use the ip command (newer syntax) to route all traffic via 192.168.1.254 gateway connected via eth0 network interface for example:

ip route add 192.168.1.0/24 dev eth0

or

ip route add 192.168.1.0/24 via 192.168.1.254

For remove gateway in Linux Command : route delete default gw 192.168.1.1 eth1

For add gateway in Linux Command : route add default gw 192.168.1.250 eth1

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.