How to set the Default gateway

226,788

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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
Share:
226,788

Related videos on Youtube

Abdessamad Doughri
Author by

Abdessamad Doughri

Updated on September 18, 2022

Comments

  • Abdessamad Doughri
    Abdessamad Doughri over 1 year

    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?

    • Rui F Ribeiro
      Rui F Ribeiro over 8 years
      Please specify which embedded Linux you are using.