Linux eth0 static ip

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.

Источник

linux-notes.org

Настройка статического IP адреса в Unix/Linux

Хотел представить настройку статического IP на различные Unix/Linux ОС.

Читайте также:  Linux mint убрать запрос пароля при входе

Настройка статического IP адреса в Debian/Ubuntu/Linux Mint

Недавно столкнулся с проблемой, нужно было настроить статический IP в Debian/Ubuntu/Linux Mint, по этому решил еще и написать статейку. Думаю что кому то и будет интересна она, может и поможет. В теме «Настройка статического IP адреса в Debian/Ubuntu/Linux Mint» я расскажу как это можно сделать на готовом, моем примере.

1. Я использую DHCP для получения автоматического IP адреса.

Покажет нам какие у нас есть интерфейсы в системе.

2. Настройка статического IP-адреса на Ubuntu / Debian

3. Настройка DNS-сервера для Ubuntu / Debian

4. Перезагрузим сеть и проверим статический IP-адрес на Ubuntu / Debian

вывод настроеннго статического IP командой ip addr в Debian

Или как я это сделал командой:

вывод настроеннго статического IP командой ifconfig в Debian

Настройка статического IP адреса в CentOS/Fedora/RedHat

Люди часто забывают, процесс присвоения статического IP-адреса из командной строки Linux.

Устанавливаем ваш IPадрес:

Устанавливаем дефолтный шлюз (gateway):

Устанавливаем (добавляем) DNS сервер:

Assuming you have valid addresses for yourself and your gateway (and you have a clear path the the Interweb) you’re all set. Test by pinging someone.:

Настройка статического IP адреса в Unix/Linux завершена.

Источник

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:

  1. RHEL / Red hat / Fedora / CentOS Linux eth0 config file – /etc/sysconfig/network-scripts/ifcfg-eth0
  2. RHEL / Red hat / Fedora / CentOS Linux eth1 config file – /etc/sysconfig/network-scripts/ifcfg-eth1
  3. 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
Читайте также:  Как проверить когда включался компьютер windows

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.

Источник

Читайте также:  Не запускается меню параметры windows 10
Оцените статью