2

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

When I use ifconfig 10.10.10.134 netmask 255.255.255.0 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). – Henrik - stop hurting Monica Jun 14 '16 at 15:42
  • In particular, the routing table before and after might be informative. – thrig Jun 14 '16 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? – roaima Jun 14 '16 at 16:25
  • This is probably a question to be referred to the guy who runs your firewall / NAT device. – hymie Jun 14 '16 at 17:24
  • netstan -rn gives me this – xtremelampshade Jun 14 '16 at 17:47
4

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 10.10.10.134/24 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 10.0.2.2 dev eth0
10.0.2.0/24 dev eth0  proto kernel  scope link  src 10.0.2.15
10.1.1.0/24 dev eth1  proto kernel  scope link  src 10.1.1.2

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

default via 10.0.2.2 dev eth0

while default stands for 0.0.0.0/0 matching any IP address. This will cause all traffic to be routed to the router with IP 10.0.2.2 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>

while

  • <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:

nameserver 8.8.8.8
nameserver 8.8.4.4

or by simply entering:

echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf
  • I considered giving you -1 for misspelling my name :-( – Henrik - stop hurting Monica Jun 15 '16 at 15:18
  • @Henrik I am sorry for misspelling your name. – rda Jun 15 '16 at 16:49

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.