-2

I want to set the gateway to the particular interface via shell script.

We can modify the ethernet configuration file like this

DEVICE="eth0"
BOOTPROTO="static"
HWADDR=20:89:84:c8:12:8a
NM_CONTROLLED="no"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=192.168.0.108
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
DNS1=8.8.8.8
DNS1=8.8.4.4

But I want to do it the ip command way. What will be the equivalent ip command to achieve this?

Ganesh Satpute
  • 3,664
  • 6
  • 41
  • 78

1 Answers1

0

You could start with this little intro to the ip commands or this ip commands cheat sheet. With those, you can set IPADDR, e.g.

sudo ip addr add 192.168.0.108 dev eth0

The GATEWAY is set by

sudo ip route add 0.0.0.0/0 via 192.168.0.1 dev eth0

The sudo is needed only, if the user is not root.

More work is to be done for the rest and not all of them are ip commands. E.g. DNS servers are set in the /etc/resolv.conf file and not by an ip command.

Olli
  • 1,621
  • 15
  • 18