0

I have linux Fedora.

I am trying to change the local ip address by 2 ways:

  1. With sudo ifconfig <interface_name> <ip_address> netmask <netmask_address>
  2. With ip -

    sudo ip link set dev <interface_name> down
    sudo ip addr add 192.168.1.12/24 dev <interface_name>
    sudo ip link set dev <interface_name> up
    

in both ways ping works but Internet connection seems to be down and doesn't work at all.

I looked at this links:

but I didnt really got the answer I was looking for.

Chris Davies
  • 116,213
  • 16
  • 160
  • 287
Shay
  • 1

1 Answers1

1

You have successfully changed the local IP address. But as the link is shut down for changing the IP address, one other piece of information gets automatically deleted from the active network configuration: the address of the default gateway or router.

The default gateway is a thing on the network that has the connection to (most of) the other networks beyond the local one. On a home network, that would usually be your router, cable modem, or whatever device that has the long-range connection to the internet. If you have multiple network segments that are not all connected to a single backbone segment, you might need to configure other gateway addresses - but the default gateway address is always required for internet connections. Simple networks will generally only need the default gateway route specification.

The combination of a gateway address and a specification of which network(s) can be reached through that gateway is known as a route specification, or usually just "route" for short. A default gateway route is a route that will be used to reach all networks that don't match any more specific route that is defined.

A gateway address must always be reachable directly, i.e. it must be in the same network segment your system is in. If the gateway is in a different network segment, you would need to use another gateway first to reach the target gateway - and once your traffic goes through a gateway, it decides where the traffic is going next based on its routing table. A gateway system has usually several IP addresses, one for each network segment it's connected to.

It is a common convention to place the default gateway as either the first or the last regular IP address in a network segment. As you specify your IP address as 192.168.1.12/24, that means your netmask is 255.255.255.0 (= a netmask with 24 1 bits out of 32) and your network address is 192.168.1.0. So the first regular IP address in this network would be 192.168.1.1, and the last one would be 192.168.1.254.

After using the commands you specified in the question, you would need to use either of the following commands:

sudo route add default gw <default gateway address>

or

sudo ip route add default via <default gateway address>

In both commands, the word default is equivalent to 0.0.0.0/0 which means "any IPv4 network".

telcoM
  • 96,466
  • hey, Thx for the help. But I changing my ip and then I adding your code + my deafult gateway address and I get this error: "any valid address is expected rather than" @telcoM – Shay Apr 17 '20 at 20:27
  • sometimes I am getting: "Unknown host" or "network is unreachable" @telcoM – Shay Apr 17 '20 at 20:35