Key binding for DHCP and Static IP

How can I set a keybinding to set the network interface to both dhcp and a specific static ip to be able to switch back and forth between them quickly?
Thank you

There’s no easy way of doing this.

Changing network settings needs root-level access (so sudo or a polkit rule), and therefore you’d need to create a script with the correct permissions that is triggered with a keyboard shortcut. It also needs you to take down and bring back up the network each time.

Are you sure this is the problem you’re trying to solve?


Welcome to the forum!

Can you share some additional information?

Which DE are you using? Are you using network manager?

Couldn’t you just create two connections in Network Manager and toggle between them?

I know you can do this through the applet. Would have to find an easy to way to trigger that through the keyboard shortcut.

In the absolute worst case you could use a polkit rule and nm-cli but they may be an easier solution.

Yes, but you can’t toggle between them with a keyboard shortcut - it would still need some sort of script to do it (e.g. with nmcli as you suggest).

It is a very particular inconvenience I would like to overcome not a problem to solve.

Default Xfce and network manager.

My question was more around why you are wanting to do this, i.e. why do you need to frequently toggle between a static and DHCP IP address?

It is work related I can’t really tell you so much about it.

That’s OK, given this is work-related I can bill for my time and sign an NDA.

PM me and we can work something out.


I would probably do what I recommended above. Create a second connection in network manager with different ipv4/ipv6 rules. That would let you easily switch back and forth using the NM applet.

If you want it to be keyboard driven, create a shortcut that calls nmcli.

Like this: nmcli connection up <id>

Example: nmcli connection up "Wired connection 1"

If the two connections use the same interface, bringing one up will automatically bring the other one down.

For me, either switching connections doesn’t require root or the Arch polkit rules allow it by default.


You could also assign an additional static address next to the DHCP one.

F.e.: With network manager

Not sure if it fit’s you use case though.