4

I have a linux server which needs to be set up with production ip address and hostname before installation procedures start (some scripts use these variables).

I've seen somebody assigning a temporary ip address and a temporary gateway simply by typing a couple of commands, but I can't remember.

4 Answers 4

8

ifconfig is deprecated, but it still works.

The "correct" way would be:

sudo ip addr add <extra ip> dev eth0:0
2
  • Depreciated ... where have I been ... Aug 4, 2009 at 11:45
  • You may want a /subnet on the end of the extra ip (e.g. 192.168.1.100/24). Also note, you can delete IPs again by replacing add with del.
    – mwfearnley
    Oct 24, 2023 at 10:42
2

Think I found it, but it might be worth sharing anyway:

ifconfig eth0:0 <extra ip> up
sudo route add default gw <gatewayip>
2

I just want to add something on blauwblaatje's answer. https://serverfault.com/a/49651/575693

sudo ip addr add <ip/cidr> dev eth0

If you don't put cidr notation, the host will be configured as host only or /32. Hence, you won't be able to communicate with other machine.

Avoid the following example unless you don't need networking. E.g.

sudo ip addr add 172.16.1.1 dev eth0

same as

sudo ip addr add 172.16.1.1/32 dev eth0

Instead, define your subnet based on your requirement, let say Class C or /24

sudo ip addr add 172.16.1.1/24 dev eth0
0

The command will add an alias to the interface so yes it is in addition to the current one. If you need to add a netmask then the command would look like:

sudo ifconfig eth0:1 <ip> netmask <mask> up

Otherwise ifconfig will use the default for the Class the IP belongs to e.g. 255.255.255.0 for Class C

Just be careful with the default route option. You generally only want one default route so you may want to remove the current default route before adding the new one, otherwise play around with the metric on the route.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .