- How to Set Static IP Address and Configure Network in Linux
- Configure Static IP Address in RHEL/CentOS/Fedora:
- Set Static IP Address in Debian / Ubuntu
- Conclusion:
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- How to set up static IP address on Debian Linux 10/11
- How to static IP address on Debian Linux
- Finding your network interfaces name on Debian Linux
- Configuring Static IP on Debian 10 or 11
- Restart networking service on Debian Linux to switch from DHCP to static IP config
- See your new IP address assigned on Debian Linux
- Conclusion
- Linux Static IP Address Configuration
- Sample Setup: Linux Static TCP/IP Settings
- RHEL / Red hat / Fedora / CentOS Linux Static IP Configuration
- Debian / Ubuntu Linux Static IP Configuration
- See also:
How to Set Static IP Address and Configure Network in Linux
If you are a Linux system administrator, time will come when you will need to configure networking on your system. Unlike desktop machines where you can use dynamic IP addresses, on a server infrastructure, you will need to setup a static IP address (at least in most cases).
This article is meant to show you how to configure static IP address on most frequently used Linux distributions.
For the purpose of this tutorial, we will use the following Internet Protocol version 4 (IPv4) details:
Configure Static IP Address in RHEL/CentOS/Fedora:
To configure static IP address in RHEL / CentOS / Fedora, you will need to edit:
Where 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:
Open that file and set:
Note: 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:
You will only need to edit the settings for:
Other settings should have already been predefined.
Next edit resolve.conf file by opening it with a text editor such as nano or vi:
Once you have made your changes restart the networking with:
Set Static IP Address in Debian / Ubuntu
To setup static IP address in Debian/ Ubuntu, open the following file:
You may see a line looking like this:
Change it so it looks like this:
Save the file and then edit /etc/resolv.conf like this:
Restart the networking on your system with:
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.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
How to set up static IP address on Debian Linux 10/11
I have Debian 10 Linux cloud server, and it is configured to get IP addresses via DHCP. How do I convert DHCP address to static IP address settings?
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Debian Linux |
Est. reading time | 3 minutes |
By default, the DHCP server will provide IP information in your network. Your DHCP client on Debian Linux will obtain an IP address, subnet, default route, DNS server/resolvers IP address, and other information configured on the DHCP server. Let us see how to add, configure and set up a static IP address on Debian Linux version 9/10/11.
How to static IP address on Debian Linux
The procedure is as follows to set up and configure a static IP information:
- Open the terminal application.
- Log in to remote or server using ssh command.
- Backup /etc/network/interfaces file running sudo cp /etc/network/interfaces /root/
- Edit the /etc/network/interfaces
- Configure static IP address for enp0s5 Ethernet interface: address 192.168.2.249
- Add subnet mask: netmask 255.255.255.0
- Set up default gateway IP: gateway 192.168.2.254
- Finally add DNS resolver IP: dns-nameservers 192.168.2.254 8.8.8.8 1.1.1.1
Let us see all commands and examples in details.
Finding your network interfaces name on Debian Linux
Use the ip command as follows to show/display available Ethernet network interfaces:
ip -c link show
Also, we can try the following Linux command to show a list of network cards:
sudo lshw -class network -short
lspci | egrep -i —color ‘network|ethernet|wireless|wi-fi’
ip -br -c link show
Note down the Debian Linux interface name and type the following ip command to see the current IP address assinged to that network interface:
ip -c addr show enp0s5
Finding NIC name and IP assigned by the DHCP server on Debian Linux
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Configuring Static IP on Debian 10 or 11
The /etc/network/interfaces[/file] contains network interface configuration information for Debian Linux. Hence, edit the file:
sudo vim /etc/network/interfaces
## OR ##
sudo nano /etc/network/interfaces
Look for the primary network interface enp0s5:
Remove dhcp and allow-hotplug lines. Append the following configuration to set up/add new static IP on Debian Linux 10/11. Here is my sample config file:
Restart networking service on Debian Linux to switch from DHCP to static IP config
Warning : Do not run the following over ssh based session as you will disconnect.
Use the systemctl command as follows:
sudo systemctl restart networking.service
Make sure service restarted without any errors. Hence, type the following command:
sudo systemctl status networking.service
Sample session:
See your new IP address assigned on Debian Linux
Conclusion
You learned how to convert the existing DHCP to static IP address settings on Debian Linux version 9/10/11. See Debian Linux man page online or type the following command:
man interfaces
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Источник
Linux Static IP Address Configuration
H ow do I configure the Internet Protocol version 4 (IPv4) properties of a network connection with a static IP address for servers running Linux operating systems? How do I configure static IP address under Debian Linux or Redhat / RHEL / Fedora / Redhat Enterprise Linux server?
You need to update and/or edit the network configuration files. This tutorial provides procedures to configure a static IP address on a computer running the following operating systems:
- RHEL / Red hat / Fedora / CentOS Linux eth0 config file – /etc/sysconfig/network-scripts/ifcfg-eth0
- RHEL / Red hat / Fedora / CentOS Linux eth1 config file – /etc/sysconfig/network-scripts/ifcfg-eth1
- Debian / Ubuntu Linux – /etc/network/interfaces
Sample Setup: Linux Static TCP/IP Settings
In this example you will use the following Internet Protocol Version 4 (TCP/IPv4) Properties including IP, default gateway, and preferred DNS servers:
- IP address: 192.168.1.10
- Netmask: 255.255.255.0
- Hostname: server1.cyberciti.biz
- Domain name: cyberciti.biz
- Gateway IP: 192.168.1.254
- DNS Server IP # 1: 192.168.1.254
- DNS Server IP # 2: 8.8.8.8
- DNS Server IP # 3: 202.54.2.5
RHEL / Red hat / Fedora / CentOS Linux Static IP Configuration
For static IP configuration you need to edit the following files using a text editor such as vi. Edit /etc/sysconfig/network as follows, enter:
# cat /etc/sysconfig/network
Sample static ip configuration:
Edit /etc/sysconfig/network-scripts/ifcfg-eth0, enter:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0
Sample static ip configuration:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Finally, you need to restart the networking service, enter:
# /etc/init.d/network restart
To verify new static ip configuration for eth0, enter:
# ifconfig eth0
# route -n
# ping 192.168.1.254
# ping google.com
Debian / Ubuntu Linux Static IP Configuration
Edit /etc/hostname, enter:
# cat /etc/hostname
Sample ip config:
Edit /etc/network/interfaces, enter:
# cat /etc/network/interfaces
Sample static ip config:
Finally, you need to restart the networking service under Debian / Ubuntu Linux, enter:
# /etc/init.d/networking restart
Type the following commands to verify your new setup, enter:
# ifconfig eth0
# route -n
# ping google.com
See also:
- RHEL / Redhat / CentOS / Fedora Linux network configuration tutorial using GUI and config files.
- Debian / Ubuntu Linux network configuration tutorial
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Very helpful…thanks alot
YAY, easy as pie, thanks.
i am facing problem her in Ubuntu server i made static IP and it worked as ping from it and to it . after 5 min i can not ping to ubuntu but i used ifconfig i found my ip as it is and ping from ubunto to any pc is fine, i made ifdown then ifup it works again but after about time stopped ping from outside….
Sounds like you have another machine useing the ip address,
try doing ifdown and then ping from another machine to your ip address if you get reply, change your static ip to one that gets no respose do a ping first to check if the ip is in use, this way you can ensure you have a unique address, if using a dhcp make sure you add a reservation into it else it could happen again where the server is not getting a lease so the dhcp will assign on request to a machine, good idea is to set your dhcp range to something like xxx.xxx.xxx.100 – 200 and then you know you can freely use any ip up to xxx.xxx.xxx.99 and not have to add it in the reservations because the dhcp wont assign below 100
But if I have two NIC cards and I have to give different hostnames for evry ip.
Is this possible?
example
NIC 1 : 192.168.1.1
HOSTNAME : server1.abcd.com
NIC 2 : 192.168.2.1
HOSTNAME : server2.xyzf.com
So is this possible on one system??
In DNS server I have made this entry.
How can I resolve this ip/hostname from the machine itself.
I am new in this field. Please advise me.
( I guess I can do this entries in /etc/hosts. Is this right??)
in /etc/hosts
192.168.1.1 server1 server1.abcd.com
192.168.2.1 server2 server2.xyzf.com
Awesome, helped me out using Raspberry Pi Debian.
Thanks, I was able to resolve my ip addressing problem…now it’s not resolving dns and yes I added the dns ip’s to resolv.conf. What a nose bleed!
Is it just me or or is just beyond stupid Centos has problems connecting to the net out of the box. Reallllly?
I don’t want DHCP to push DNS info in my resolv.conf. How do I achieve that?
What I tried and didn’t help:-
1.Disable dns in /etc/nsswitch.conf
2.Disable dns in /etc/resolv.conf
3.Service network restart (obtain IP from DHCP)
4.Check resolv.conf to discover that dns ip is written in resolv.conf again!
PEERDNS=, where is one of the following:
yes — Modify /etc/resolv.conf with information from the server. If using DHCP, then yes is the default.
no — Do not modify /etc/resolv.conf.
Cyberciti, whenever I come here, I am done with my solution. Thank you so much.
Keep it up 🙂
-Vimal
on HREL/CentOS it didn’t work.
After restarting it connected, (pinged google ok) but pinging the IP I set returned unknown host
dont forget “auto eth0”
For set Centos Static IP Address Configuration need this configuration
DEVICE=eth0
BOOTPROTO=none
HWADDR=e0:66:90:03:98:5b
IPADDR=192.168.2.3
NETMASK=255.255.255.0
ONBOOT=yes
GATEWAY=192.168.2.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
Hi i have this strange problem that on centOS running inside VirtualBox i set the IP Address and after sometime the configurations are lost and the interface has no IP Address. I have no clue why this is happeneing?
Can someone please help. Its like i setup everything restart, fine i have ip there but after like a min or 40+ seconds configurations are lost. i set again with ifconfig, they stay for sometime and then reset again, what should i do?
thanks a lot it’s perfect explain
I was suffering from IP problem between VMware and local computer there isn’t connection when I was using Putty to do connect to linux on VMware.
once again thanks million *_^
Good useful information. It was very helpful
thanks a lot dear please keep sharing this kind to knowledge to our all linux users.
Doesn’t look like it’ll work when you need something like this.
ip a a 127.0.0.1/8 dev lo
ip a a 8.8.8.8/32 dev lo
thanks its very help full site for user but one request for you Add search box in web page for finding more details which i want.
Источник