If you are a Linux system administrator, there will come a time when you need to configure the network on your system. Unlike desktops where you can use dynamic IP addresses, on server infrastructure you'll need to set up a static IP address (at least in most cases).
Assumptions:
IP: 192.168.0.100 Netmask : 255.255.255.0 hostname: vps.tino.org Gateway: 192.168.0.1 DNS Server first: 8.8.8.8 DNS Server 2: 4.4.4.4
Configure Static IP Addresses in RHEL / CentOS / Fedora:
Configuration file:
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-eth0
File "ifcfg-eth0" configures for the interface eth0 network card. If your theme is named eth1 ″ then the file you need to edit is “ifcfg-eth1”.
You can check the network cards on VPS with the command:
ifconfig -a
Hoặc
ip addr
Configure file: / etc / sysconfig / network
Edit with the command:
# vi /etc/sysconfig/network
Open that file and set:
NETWORKING=yes
HOSTNAME=vps.tino.org
GATEWAY=192.168.0.1
NETWORKING_IPV6=no
IPV6INIT=no
Edit next file:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Note: Make sure you open the correct network card configuration file.
Change information:
DEVICE="eth0"
BOOTPROTO="static"
DNS1="8.8.8.8"
DNS2="4.4.4.4"
GATEWAY="192.168.0.1"
HOSTNAME="vps.tino.org"
HWADDR="00:19:99:A4:46:AB"
IPADDR="192.68.0.100"
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="8105c095-799b-4f5a-a445-c6d7c3681f07"
You just need to edit the following values:
- DNS1 and DNS2
- GATEWAY
- HOSTNAME
- NETMASK
- IPADDR
Next you configure the DNS resolution server management file.
resolve.conf
You can edit it with the software Because or nano
# vi /etc/resolv.conf
nameserver 8.8.8.8 #
nameserver 4.4.4.4 #
Once you have made your changes restart the networking with:
# /etc/init.d/network restart [On SysVinit]
# systemctl restart network [On SystemD]
Set static IP addresses in Debian / Ubuntu
To set up an internal static IP address Debian / Ubuntu Open the following file:
# nano /etc/network/interfaces
You can see a line that looks like this:
auto eth0
iface eth0 inet dhcp
Change into:
auto eth0
iface eth0 inet static
address 192.168.0.100
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 4.4.4.4
dns-nameservers 8.8.8.8
Save the file, then edit the following file:
/etc/resolv.conf
edit command:
# nano /etc/resolv.conf
nameserver 8.8.8.8
nameserver 4.4.4.4
Restart the network on VPS.
# /etc/init.d/network restart [On SysVinit]
# systemctl restart network [On SystemD]
Your static IP address is configured.
Conclude:
Now you know how to configure a static IP address on a Linux VPS. If you have any questions or comments, please feel free to post them in the comments below.
0 Comments