Configure pc network parameters manually

For learning purposes im using ip to configure a PC network parameters to the router, as opposed to receiving the parameters through DHCP.

As per DHCP (router) this are the current network parameters:

wlp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.33  netmask 255.255.255.0  broadcast 192.168.1.255

And the route is:

ip route
default via 192.168.1.1 dev wlp1s0 proto dhcp metric 600
169.254.0.0/16 dev wlp1s0 scope link metric 1000
192.168.1.0/24 dev wlp1s0 proto kernel scope link src 192.168.1.33 metric 600

So I want to reproduce a similar config using commands. This is the proceduce I'm following:

  1. Turn off wireless card communication: ip link set wlp1s0 down
  2. New ip address for my W. Card: sudo ip addr add 192.168.1.42/24 dev wlp1s0
  3. Add a default gateway: sudo ip route add default via 192.168.1.1

But I get this error: Error: Nexthop has invalid gateway.

I'm not sure yet, if netplan should be such that dhcp4 is set to false. But in any case the error gotten is unexpected to me. Any help?

Any help?

Edit: I'm following this ubuntu tutorial


You are adding route via NIC which is down (you put it down in the first command). This won't work; for a default route to be added, the interface through it is going should be up.

I don't understand why you are turning wlp1s0 down in the first place. You should manipulate network addresses while NIC is up and running.


A route needs an outgoing interface specified. While you can omit that in your instruction when adding an indirect route, the prerequisite is that a direct route for the gateway has already been added, so that ip route (or maybe the kernel; I don't really know if it's like a static or dynamic "linkage") can get the interface from that for the former.

Because you've brought the interface down, the prefix route (e.g. 192.168.1.0/24 dev wlp1s0), which is a direct route that covers 192.168.1.1, will not be added by the kernel to the route table until you brought it up again.

Therefore, the gateway is "invalid", as no route that covers the address is found in the route table.

In fact, if you try to add e.g. 192.168.1.1 dev wlp1s0 manually, you will see the reason:

$ ip a show wlan0
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 3c:9c:0f:7d:89:3a brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.150/24 scope global wlan0
       valid_lft forever preferred_lft forever
$ sudo ip r add 192.168.1.1 dev wlan0
Error: Device for nexthop is not up.

(And naturally, ip r will also output nothing.)