CentOS instructions

Post Reply
User avatar
Edge100x
Founder
Founder
Posts: 12219
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

CentOS instructions

Post by Edge100x » Mon Jun 13, 2011 12:36 pm

To change the IPs in CentOS, log in to your server through SSH or the "VNC Console" page in the control panel, and then use the nmtui command for a menu-driven system. You can use enter to select the "eth0" interface, then use tab and enter to move between fields and make the necessary edits.

If this is unavailable, you can edit the IPs by hand. If you need to edit the main IP for the machine after a location change,
  1. Open the file /etc/sysconfig/network-scripts/ifcfg-eth0 in your favorite text editor (if you are new to text editing on Linux, we recommend installing nano with yum install nano and then running the command nano /etc/sysconfig/network-scripts/ifcfg-eth0).
  2. You should see your primary IP and netmask (from the "IP list" control panel page) in this file. Edit the IPADDR= and NETMASK= fields to match your new IP address.
  3. Save the file and exit.
  4. Open /etc/sysconfig/network in your text editor.
  5. Edit the GATEWAY= field to match the gateway of the IP you entered above.
  6. Save the file and exit.
  7. Reboot the VDS with the "reboot" command.
If you have extra (secondary) IPs to add, it's best to keep these into separate files. Look for /etc/sysconfig/network-scripts/ifcfg-eth0:x files (where x is an integer) and edit them as you did the main file above.

If you need to delete an IP, find its corresponding ifcfg-eth0:x file and delete it.

If you need to add an IP on top of your existing assignments,
  1. Look for the highest numbered /etc/sysconfig/network-scripts/ifcfg-eth0:x file.
  2. Create a new file called /etc/sysconfig/network-scripts/ifcfg-eth0:y, where y is one higher than x.
  3. Place these lines in the file:
    DEVICE=eth0:y
    BOOTPROTO=static
    IPADDR=newip
    NETMASK=newnetmask
    ONBOOT=yes
    newip and newnetmask need to match the assignment information we gave you.
  4. Save the file and exit.
  5. If necessary, edit /etc/sysconfig/network to set a new gateway (note that you should only ever list one gateway -- if you already have one for an existing IP address that you are also keeping, you should retain it).
  6. Reboot the VDS with the "reboot" command.

User avatar
Vanderburg
Staff
Staff
Posts: 1134
Joined: Sat Nov 13, 2010 7:27 am
Location: Dallas, TX

Re: CentOS instructions

Post by Vanderburg » Tue Sep 06, 2016 1:42 pm

On full machines, the main interface file might have a different name, such as ifcfg-enp#s# (e.g. ifcfg-enp2s0). If so, follow the instructions as above, but replace eth0 with the part after ifcfg-, such as enp2s0.

You can find your adapter name with these commands:

Code: Select all

cd /etc/sysconfig/network-scripts
ls
In that output, the first one or more files should start with ifcfg-something. You can see the contents of a file with this command (replacing the filename with what you want to view):

Code: Select all

cat ifcfg-eth0
Look at the files without a colon until you see one that has your IP address in it (as shown on the "IP list" page of your control panel). This is the main interface that you will branch from.

User avatar
Edge100x
Founder
Founder
Posts: 12219
Joined: Thu Apr 18, 2002 11:04 pm
Location: Seattle
Contact:

Re: CentOS instructions

Post by Edge100x » Thu Jun 06, 2019 9:37 am

Another valid option is to put all of the IP addresses into a single file, instead of using separate files.

If you do this, you need to give each address (and its corresponding prefix or netmask) a unique identifier by adding a number to the end of it. For instance, your current /etc/sysconfig/network-scripts/ifcfg-eth0 file may say:

Code: Select all

DEVICE=enp2s0
BOOTPROTO=static
IPADDR=1.1.1.1
PREFIX=24
ONBOOT=yes
If you wanted to add IP address 1.1.1.2, you could change it to:

Code: Select all

DEVICE=enp2s0
BOOTPROTO=static
IPADDR=1.1.1.1
PREFIX=24
IPADDRESS0=1.1.1.2
PREFIX0=24
ONBOOT=yes
It is also valid to specify a netmask instead of a prefix, because this gives the OS the same information about the local network. For instance, because a /24 is the same as netmask 255.255.255.0, you could instead use:

Code: Select all

DEVICE=enp2s0
BOOTPROTO=static
IPADDR=1.1.1.1
PREFIX=24
IPADDRESS0=1.1.1.2
NETMASK0=255.255.255.0
ONBOOT=yes
In our control panel, we list the netmask, so it's usually easiest to continue using the netmask in your file.

Post Reply