Building Professional Web Hosting Solution
<< Linux Basic Setup and Configuration Course
>> Linux VM/VPS Fundamental Configuration Section
- Configuring Local or Public DNS PTR Records
- Debian Based Hostname Plus Network Configuration
- Red Hat Based Hostname Plus Network Configuration
- Red Hat Based Systems Network Manager Text UI
Red Hat Based Hostname Plus Network Configuration will show you step by step how to set your Public VPS Network Configuration. The following procedures should be used as baseline across all Red Hat and CentOS base systems deployment when it comes to Network, DNS, and Hostname Settings. The Basic requirements in this article will include configuring, setting, and verifying a proper hostname, FQDN, Static IP, and hosts file to prepare your VPS for next and advanced configuration.
Objectives:
1. Setting a VPS Hostname and FQDN
2. Configuring Network Settings DO or Vultr
3. Private VM Interface Network Settings
4. Configuring Server’s Hosts Network Settings
Prerequisites:
A. Basic Domain, Sub-domain, or DNS Knowledge
B. Login to your DigitalOcean or Vultr Account
Note: Setting and Configuring basic requirements such Static IP Address, Hostname (FQDN), and Hosts File before configuring any service is a must step. Most Public VPS created ready with proper Static IPv4/IPv6 Address, Hostname, and Hosts file, regardless, it’s very important to double check these settings before configuring any service.
Recommendations:
For better performance, use VPS with at least 2 CPUs, 4G Memory, 1G Bandwidth, and SSD Storage drive.
Table of Contents
Set a VPS Hostname and FQDN
The hostname is your VPS label. The Hostname and FQDN used to represent Services and Applications that are hosted at that VPS. It’s very important to set proper hostname and FQDN since these names allow the server to communicate Internally and Externally using names instead if IP addresses. Services and Applications can represent them selves to the rest of the network and communicate with other VPSs using those names instead of static IP Address.
Public VPS Users: DigitalOcean or Vultr allows you to set a Hostname while you are creating your Droplet or instance. However, always verify it using the hostname or hostnamectl commands, if the hostname is not set as required, change it using step 2 as shown below. If you decide to change the hostname, please make sure to change the Reverse DNS records as well at your domain DNS management control panel.
Run the following steps (1 to 4)
1. Check your VPS Hostname
hostname
Or, Systemd Based such Debian8, Ubuntu16.04, or CentOS7
hostnamectl
If you believe your VPS’s Hostname was not set properly, use the next command to set a proper hostname.
2. Set or Change the VPS Hostname
a. CentOS6
First, I will make sure nano editor is installed:
yum install nano -y
Replace node1.ccnahub.com using your sub-domain.
nano /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=node1.ccnahub.com
[...]
Save: Ctrl-X, Hit Y Key, and Enter.
b. CentOS7
Install Network Configuration Tools
yum install NetworkManager-tui net-tools -y
Unmask and start the Service
systemctl unmask NetworkManager systemctl start NetworkManager
Turn On the Service at Startup
systemctl enable NetworkManager.service
Set your VPS Hostname
Replace node1.ccnahub.com using your sub-domain.
nmcli general hostname node1.ccnahub.com
Restart Hostname Service
systemctl restart systemd-hostnamed
3. Reboot and Verify Hostname
reboot
a. CentOS6
hostname
b. CentOS7
hostnamecli
Or
nmcli general hostname
4. Rename Your VPS Label if Needed
a. DigitalOcean
Navigate as shown in the image below to rename your Droplet as shown if needed. The Label name usually should reflects your Droplet hostname.
Navigate as shown in the image below to rename your Vultr Instance as shown if needed. The Label name usually should reflects your instance hostname.
Configuring Network Settings DO or Vultr
Using DigitalOcean CentOS VPS Interface
DigitalOcean configures a static Public IP address and Private IP address for Debian Based Systems using one file as shown below. If you haven’t chosen a Private IP address during VPS creation, then skip the private IP address interface configuration or verification.
Verify IP address Settings
- Navigate under your Droplet or VPS instance Settings to find the Network and IP address Settings you need to verify.
- View or display the interface file Network Settings, use cat command or nano command to view and verify the network settings.
Run the following steps (1 to 4)
1. List Network Interfaces
ls -lah /etc/sysconfig/network-scripts/ | grep -i ifcfg-eth*
I am interested in ifcfg-eth0 and ifcfg-eth1 files:
-rw-r--r--. 1 root root 399 Dec 5 15:31 ifcfg-eth0 -rw-r--r-- 1 root root 156 Dec 5 15:31 ifcfg-eth1
If you want to just view the interface file, use cat command, however, you still can use nano command as well to view the file.
First, I will make sure nano editor is installed:
yum install nano -y
2. Backup Network Interface File
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0-bak
3. View/Configure eth0 network interface file (Public IP Settings)
nano /etc/sysconfig/network-scripts/ifcfg-eth0
You Should see something similar to the following file:
Note: “none” indicates that the interface was configured using Static IP address, besides, you should see the IPv4 and 6 inside the interface.
DEVICE='eth0' TYPE=Ethernet BOOTPROTO=none ONBOOT='yes' HWADDR=04:01:f9:8d:c4:01 IPADDR=107.170.122.158 NETMASK=255.255.240.0 GATEWAY=107.170.112.1 NM_CONTROLLED='yes' IPADDR2=10.13.0.11 PREFIX2=16 IPV6INIT=yes IPV6ADDR=2604:A880:0000:1010:0000:0000:0873:3001/64 IPV6_DEFAULTGW=2604:A880:0000:1010:0000:0000:0000:0001 IPV6_AUTOCONF=no DNS1=2001:4860:4860::8844 DNS2=2001:4860:4860::8888 DNS3=8.8.8.8
Below you will an example of my VPS interface file.
TIP: Optional – just a personal preference, you will notice that I have configured and labeled each section of my interface file different than the default output, however, as long as I am using the same IP address settings then shouldn’t be a problem. Feel free to use the same format. Of course, use your VPS’s IPv4 and 6 settings instead.
Recommended Steps
- Copy the below interface file to your notepad
- Copy and use your VPS IP Addresses Settings instead
- Go back and edit your Interface file using nano editor, hit Alt-b to backup its content
- Now, have the cursor at the beginning of the file, then delete all lines using Ctrl-k keys
- Finally, copy and paste your final interface file from the notepad to your VPS’s interface file and save
Note: Remember, DigitalOcean Droplet’s Interface file already configured with Static IP address Settings, so you don’t need to edit the file unless you have too. Regardless, it’s good to view and verify the IP settings.
IPv6: As of this writing and if IPv6 network enabled for the VPS, IPv6 DNS settings sometimes doesn’t resolve properly, therefore, I placed IPv4 DNS server before IPv6 as shown below.
# Interface eth0 Configuration DEVICE='eth0' TYPE=Ethernet # DHCP or Static? none equal to Static BOOTPROTO=static ONBOOT='yes' # MAC Address >> Each VPS got its own MAC address HWADDR=04:01:8c:d7:57:01 # Public IPv6 Address IPV6INIT=yes IPV6ADDR=2604:A880:0800:00A1:0000:0000:0098:8001/64 IPV6_DEFAULTGW=2604:A880:0800:00A1:0000:0000:0000:0001 IPV6_AUTOCONF=no DNS3=2001:4860:4860::8844 DNS4=2001:4860:4860::8888 # Public IPv4 Address IPADDR=159.203.126.30 NETMASK=255.255.240.0 GATEWAY=159.203.112.1 NM_CONTROLLED='yes' DNS1=8.8.4.4 DNS2=8.8.8.8 # Floating IP Settings # There is no need for Floating IP right now, however, you can keep it. IPADDR2=10.17.0.11 PREFIX2=16
Save: Ctrl-X to exit, Hit Y Key, and Enter.
If you changed the network settings, restart the network service:
service network restart
Next, verify the Private IP address settings of eth1.
4. View/Configure eth1 network interface file (Private IP Settings)
Verify Private IP Address Settings
nano /etc/sysconfig/network-scripts/ifcfg-eth1
You don’t need to edit the file, just make sure the Private IP address matches your VPS Private IP. If not, please fix it, save, and restart the network service.
# Interface eth1 Configuration DEVICE='eth1' TYPE=Ethernet # DHCP or Static? none equal to Static BOOTPROTO=none ONBOOT='yes' # MAC Address >> Each VPS got its own MAC address HWADDR=04:01:8c:d7:57:02 # Private IPv4 Address IPADDR=10.132.15.129 NETMASK=255.255.0.0 DEFROUTE='no' NM_CONTROLLED='yes'
Save: Ctrl-X to exit, Hit Y Key, and Enter.
If you changed the network settings, restart the network service:
service network restart
Using Vultr CentOS VPS Interface
As of this writing, Vultr might not configure your VPS interface with Static IP addresses the way DigitalOcean does, which is not a big deal. Switching to Static IP Address Settings can be done using the interface template as shown below.
Note: using CentOS, Vultr instruct us to configure Public IP address and Private IP address using different interface files as shown below. If you haven’t chosen a Private IP address during VPS creation, then skip private IP address interface configuration.
Run the following steps (1 to 5)
I am interested in ifcfg-eth0 and ifcfg-eth1 files, however, at Vultr ifcfg-eth1 is not created during VPS creation. I can create the file manually.
1. List Network Interfaces
ls -lah /etc/sysconfig/network-scripts/ | grep -i ifcfg-eth*
As you can see, and as of this writing, the output shows only ifcfg-eth0; ifcfg-eth1 is not created when Vultr VPS created. I will show you below how to create ifcfg-eth1 manually if needed.
-rw-r--r-- 1 root root 156 Oct 27 17:40 ifcfg-eth0
Make sure nano editor is installed:
yum install nano -y
2. Backup Network Interface File
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0-bak
3. Configure eth0 network interface file (Public IP Settings)
nano /etc/sysconfig/network-scripts/ifcfg-eth0
You Should see something similar to the following file:
As of this writing, Vultr won’t configure your VPS interface as Static.
DEVICE="eth0" BOOTPROTO="dhcp" ONBOOT="yes" TYPE="Ethernet" NM_CONTROLLED="no" DNS1=108.61.10.10 IPV6_AUTOCONF=yes IPV6INIT=yes #DNS2=2001:19f0:300:1704::6
Below you will an example of my VPS interface file which you can use.
TIP: Optional – just a personal preference, you will notice that I have configured and labeled each section of my interface file different than the default output, however, as long as I am using the same IP address settings then shouldn’t be a problem. Feel free to use the same format. Of course, use your VPS’s IPv4 and 6 settings instead.
Recommended Steps
- Copy the below interface file to your notepad
- Copy and use your VPS IP Addresses Settings instead
- Go back and edit your Interface file using nano editor, hit Alt-b to backup its content
- Now, have the cursor at the beginning of the file, then delete all lines using Ctrl-k keys
- Finally, copy and paste your final interface file from the notepad to your VPS’s interface file and save
Note: As per Vultr Support, I recommend configuring all instances statically as shown below. However, when deploying a new VPS from a snapshot, remember to change the old static IP address to match the newly assigned IP address. But, if you elect to deploy a new instance with a pre-reserved IP address, this would not be necessary as the IP would carry over.
Besides, there is the blue “network configuration examples” link under your VPS instance “Settings” tab, includes all necessary file paths and configurations for network settings. Last but not least, remember that not all the VPS instances use the interface name “eth0”, some instances such Ubuntu16 might use different interface name. Always refer to your VPS “Settings” tab to make sure you are using the proper format.
# Interface eth0 Configuration DEVICE=eth0 TYPE=Ethernet # DHCP or Static? none equal to Static BOOTPROTO=static ONBOOT=yes # Public IPv6 Address IPV6INIT=yes IPV6ADDR="2001:19f0:0:201d:5400:00ff:fe27:d605/64" IPV6_AUTOCONF="yes" DNS1=2001:19f0:300:1704::6 DNS2=2001:4860:4860::8888 # Public IPv4 Address IPADDR=104.238.128.228 NETMASK=255.255.252.0 GATEWAY=104.238.128.1 DNS3=108.61.10.10 DNS4=8.8.8.8
Save: Ctrl-X to exit, Hit Y Key, and Enter.
4. Reboot the VPS
reboot
Next, Create Private IP address Interface file if needed.
5. Create eth1 network interface file (Private IP Settings)
nano /etc/sysconfig/network-scripts/ifcfg-eth1
Copy paste the following interface file inside the ifcfg-eth1 file, however, replace IPADDR field settings using your VPS Private IP Address.
# Interface eth1 Configuration DEVICE=eth1 TYPE=Ethernet # DHCP or Static? none equal to Static BOOTPROTO=static ONBOOT=yes # Private IPv4 Address IPADDR=10.99.0.10 PREFIX=16 DNS1=8.8.8.8 MTU=1450
Save: Ctrl-X, Hit Y Key, and Enter.
Restart the network service:
service network restart
Private VM Interface Network Settings
Using Private Virtualization Platform such VirtualBox or VMware Station, your Interface name might look different than “eth0”. So ,all you need to do is to set your Interface settings as Static IP similar to what is showing below. A private VM running at VirtualBox, VMware Station, or Proxmox, can be configured with static IP Address similar to the following interface:
TIP: The easiest way to edit or change your CentOS VM Interface is to use Text User Interface instead of nano using Red Hat Based Systems Network Manager Text UI.
CentOS7 Interface
TYPE="Ethernet" BOOTPROTO=static DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" NAME="enp0s3" UUID="0d5fcfb3-c0ce-4669-8f25-7be1ba63a5f9" DEVICE="enp0s3" ONBOOT="yes" IPADDR=192.168.1.49 PREFIX=32 GATEWAY=192.168.1.1 DNS1=192.168.1.1 DNS2=8.8.8.8 DOMAIN=ccnahub.com IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_PRIVACY=no
CentOS6 Interface
Edit Network Interface
nano /etc/sysconfig/network-scripts/ifcfg-eth0
# Interface eth0 Configuration, # yours might look different. NAME="System eth0" DEVICE=eth0 TYPE=Ethernet DEFROUTE=yes PEERDNS=yes PEERROUTES=yes # MAC Address >> yours should be different. HWADDR=08:00:27:F3:9A:FD # Network Manager Control NM_CONTROLLED=no # The UUID is used by the Network Manager, # yours might look different. # Disregard if Network manager not Used # UUID=0f33485f-89cb-4436-8e0d-59753ce103a8 # Startup the Interface at Boot time ONBOOT=yes # Is it a Static or dhcp BOOTPROTO=static # IPv4 Address Settings IPV4_FAILURE_FATAL=yes IPADDR=192.168.1.48 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS1=192.168.1.1 DNS2=8.8.8.8
To add Virtual Interface that carry different IP Address:
nano /etc/sysconfig/network-scripts/ifcfg-eth0:1
# eth0:1 configuration DEVICE=eth0:1 BOOTPROTO=static # Bring the Interface on Boot ONBOOT=yes # eth0:1 IP Settings IPADDR=192.168.1.82 NETMASK=255.255.255.0
Configuring Server’s Hosts File Settings
The hosts file meant to map the VPS Fully Qualified Domain Name (FQDN) and it’s hostname to a static IP address. It is one of the most important basic requirements to configure after setting VPS Hostname and the Static IP Addresses.
Configure Hosts File
nano /etc/hosts
Recommended Steps
- Copy the below hosts file to your notepad
- Copy and use your VPS IP Addresses Settings instead
- Go back and edit your hosts file using nano editor, hit Alt-b to backup its content
- Now, have the cursor at the beginning of the file, then delete all lines using Ctrl-k keys
- Finally, copy and paste your final host file from the notepad to your VPS’s hosts file and save
Note: Of course, replace the Static IPv4 and IPv6 Addresses using your VPS IP Addresses, and replace node1.ccnahub.com and node1 using your VPS FQDN and hostname. Besides, note the loop addresses below (127.0.0.1 and ::1), these loop addresses must be pointed to hostname localhost and FQDN localhost.localdomain respectively as shown below.
My Public VPS hosts file:
# # IPv4 and IPv6 Hosts File # # The following lines are desirable for IPv4 capable hosts 127.0.0.1 localhost.localdomain localhost 127.0.0.1 localhost4.localdomain4 localhost4 162.243.255.108 node1.ccnahub.com node1 # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ::1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6 2604:a880:0:1010::20:f001 node1.ccnahub.com node1
Save: Ctrl-X, Hit Y Key, and Enter.
My Private VM Hosts File:
#
# IPv4 and IPv6 Hosts File
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
192.168.1.26 node1.ccnahub.com node1
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Save: Ctrl-X, Hit Y Key, and Enter.
3. Verify hosts file Info
Ping your VPS hostname
ping node1
ping6 node6
And
ping node1.ccnahub.com
ping6 node1.ccnahub.com
Public VPS Users: You should be able to ping your VPS hostname, FQDN, and get reply. If for any reason the ping is not going through, double check your host file, or contact your VPS provider.
Besides, you should be able to ping outside Networks such Google.
ping google.com
and
ping6 ipv6.google.com
Final thought, I recommend you reboot your VPS and recheck everything again such Hostname, IP Settings, and Hosts file configuration.
Recommended Readings
By Wikipedia CentOS | About CentOS | CentOS HowTos | HowtoForge CentOS7 Minimal Server
Building Professional Web Hosting Solution
<< Linux Basic Setup and Configuration Course
>> Linux VM/VPS Fundamental Configuration Section
- Configuring Local or Public DNS PTR Records
- Debian Based Hostname Plus Network Configuration
- Red Hat Based Hostname Plus Network Configuration
- Red Hat Based Systems Network Manager Text UI
LEAVE A COMMENT