I am trying to change my IP address using terminal commands.

When I use ifconfig netmask I can change the IP address and can still connect to my network (I can ping other devices), but I can no longer connect to the internet. Is there something else I should be doing, or even a different command I should be using?

  • 1
    You'll need to give us more details about your network and why you want to change your IP, before we have any chance of giving helpful advice. ifconfig should be enough, but you can also use ip(8). Commented Jun 14, 2016 at 15:42
  • 1
    In particular, the routing table before and after might be informative.
    – thrig
    Commented Jun 14, 2016 at 15:56
  • What was your IP address and netmask previously (i.e. when you could connect to the rest of the Internet)? What is current output of netstat -rn? Commented Jun 14, 2016 at 16:25
  • This is probably a question to be referred to the guy who runs your firewall / NAT device.
    – hymie
    Commented Jun 14, 2016 at 17:24
  • netstan -rn gives me this Commented Jun 14, 2016 at 17:47

1 Answer 1


As stated by @Henrik you can use ifconfig, but you should use the newer ip command from the iproute2 package if it is available on your system (it will have the same effect).

ip addr add dev <interface>

while <interface> is the interface where the IP shall be added

To be able to access the internet your routing must be setup correctly, normally those routes are handled by the dhcp-client. If you have a static IP, you have to setup the default-gateway manually.

You can check your routing table with:

ip route show

which will print out the routing table, and should look something like this:

default via dev eth0 dev eth0  proto kernel  scope link  src dev eth1  proto kernel  scope link  src

In most circumstances the internet is accessed using a default-gateway entry:

default via dev eth0

while default stands for matching any IP address. This will cause all traffic to be routed to the router with IP if the target IP address is not matched by any of the more specific routes as shown in the example above.

To add a default-gateway enter:

ip route add default via <router-IP> dev <interface>


  • <router-IP> is the IP address of the next gateway in your network
  • <interface> is the interface where you are connected to the network

Now to use the DNS system you may also have to add nameservers manually.

In linux those are specified in /etc/resolv.conf, edit the file manually and add your nameservers, as shown in the example below with google nameservers:


or by simply entering:

echo "nameserver" >> /etc/resolv.conf
echo "nameserver" >> /etc/resolv.conf
  • I considered giving you -1 for misspelling my name :-( Commented Jun 15, 2016 at 15:18
  • @Henrik I am sorry for misspelling your name.
    – rda
    Commented Jun 15, 2016 at 16:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .