How to Set Static IP Address and Configure Network in Linux
Being Linux system administrator, situations arises when it becomes necessary to configure networking on the system. Unlike desktop
machines, where you can use dynamic IP addresses on a server
infrastructure, you will need to setup a static IP address. Here is a guide to that.
IP address: 192.168.0.103 Netmask: 255.255.255.0 Hostname: hub01.tecniqa.com Domain name: tecniqa.blogspot.in Gateway: 192.168.0.1 DNS Server 1: 8.8.8.8 DNS Server 2: 4.4.4.4
Let’s start with the first file:
In that file make the following changes:
Next edit
IP address: 192.168.0.103 Netmask: 255.255.255.0 Hostname: hub01.tecniqa.com Domain name: tecniqa.blogspot.in Gateway: 192.168.0.1 DNS Server 1: 8.8.8.8 DNS Server 2: 4.4.4.4
Configure Static IP Address in RHEL/CentOS/Fedora
/etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0Where in the above
"ifcfg-eth0"
answers to your network interface eth0
. If your interface is named “eth1"
then the file that you will need to edit is "ifcfg-eth1"
.Let’s start with the first file:
# vi /etc/sysconfig/networkOpen that file and set:
NETWORKING=yes HOSTNAME=hub01.tecniqa.com //change to your hostname GATEWAY=192.168.0.1 NETWORKING_IPV6=no IPV6INIT=noNext open the following:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0Note: Make sure to open the file corresponding to your network interface. You can find your network interface name with ifconfig -a command.
In that file make the following changes:
DEVICE="eth0" BOOTPROTO="static" DNS1="8.8.8.8" DNS2="4.4.4.4" GATEWAY="192.168.0.1" HOSTNAME="hub01.tecniqa.com" HWADDR="01:23:95:E3:7F:AB" IPADDR="192.68.0.103" NETMASK="255.255.255.0" NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="8105c095-199b-4f5a-a445-b657c368170d"You will only need to edit the settings for:
- DNS1 & DNS2
- GATEWAY
- HOSTNAME
- NETMASK
- IPADDR
Next edit
resolve.conf
file by opening it with a text editor such as nano or vi:# vi /etc/resolv.conf
nameserver 8.8.8.8 # Replace with your nameserver ip nameserver 4.4.4.4 # Replace with your nameserver ipOnce you have made your changes restart the networking with:
# /etc/init.d/network restart [On SysVinit] # systemctl restart network [On SystemD]
Set Static IP Address in Debian / Ubuntu
To setup static IP address in Debian/ Ubuntu, open the following file:# nano /etc/network/interfacesYou may see a line looking like this:
auto eth0 iface eth0 inet dhcpChange it so it looks like this:
auto eth0 iface eth0 inet static address 192.168.0.103 netmask 255.255.255.0 gateway 192.168.0.1 dns-nameservers 4.4.4.4 dns-nameservers 8.8.8.8Save the file and then edit
/etc/resolv.conf
like this:# nano /etc/resolv.conf
nameserver 8.8.8.8 # Replace with your nameserver ip nameserver 4.4.4.4 # Replace with your nameserver ipRestart the networking on your system with:
# /etc/init.d/network restart [On SysVinit] # systemctl restart network [On SystemD]Your static IP address has been configured.
Conclusion:
You now know how to configure a static IP address on a Linux distro. If you have any questions or comments, please do not hesitate to submit them in the comment section below.
How to Set Static IP Address and Configure Network in Linux
Reviewed by Unknown
on
11:21:00
Rating:
No comments: