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 Answers1

5

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
rda
  • 941