2

My CentOS VPS got many IP addresses that I'd like to add to the eth0 network interface.

Currently eth0 only got 1 IPv4 address and its other ones doesn't show up.

My searching gives me terms like IP Alias but that doesn't seem to apply to CentOS. The CentOS Wiki doesn't really show how it's done.

cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0

Now you can edit the new file ifcfg-eth0:0 and specify the network settings of the virtual interface.

How do I manually add IPv4 IP addresses to a physical network interface in CentOS 7?

4
  • The Wiki tip you link to does explains how to add to add IP addresses to a network device that persists across reboots. The Wiki could be more verbose and explanatory but the information is there. Can you edit the question to highlight the part(s) you're having trouble with. Oct 8, 2017 at 12:47
  • 1
    Done. You can now edit the file. Yes, very much aware that the file is editable, but what to put in it? @AnthonyGeoghegan Oct 11, 2017 at 23:34
  • 1
    Cool. I've upvoted your question. I was going to add an answer based on referencing the documentation at access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… but it looks like Hunter's answer meets your needs. Oct 12, 2017 at 0:18
  • Well, @AnthonyGeoghegan, you link covers more ways of doing it (like scripting). Oct 12, 2017 at 0:49

2 Answers 2

6

Create a configuration file called ifcfg-<interface name>:0 in /etc/sysconfig/network-scripts/

The syntax of the configuration will be like this :

DEVICE="eth0"
BOOTPROTO="static"
ONBOOT="yes"
IPADDR=x.x.x.x
GATEWAY=x.x.x.x
NETMASK=255.255.255.0
TYPE=Ethernet

Then restart the service and you should be good to go.

service network restart
4
  • What if the gateway is assigned through DHCP? Oct 11, 2017 at 16:15
  • 1
    Comment out the line which says GATEWAY in your config. Oct 11, 2017 at 16:16
  • I am sure the issue is me but not seeing how/why. Using the above template, plug-in necessary values 'service network restart' expected results, but does not persist across boot. 'systemctl restart network' seems to have no effect. Any thoughts?
    – terary
    Jul 4, 2018 at 1:47
  • It works for me after I changed DEVICE="eth0" to DEVICE="eth0:0"
    – Shawn Hu
    Feb 16, 2023 at 12:30
2

To assign an IP just in your session, volatile until reboot:

ip a add 1.2.3.4/24 dev eth0
1
  • 2
    You can make this answer even more useful by adding a link to the man page of ip and by describing what each of the flags are used for in this case. Jan 22, 2019 at 15:38

You must log in to answer this question.

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