How to Configure a Static IP Address on Linux

Configuring a Static IP Address on Linux

Dedicated servers typically have a static IP configured by default. This guide covers how to set or change it manually.

Ubuntu 20.04+ (Netplan)

ls /etc/netplan/
nano /etc/netplan/00-installer-config.yaml
network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 203.0.113.10/24
      gateway4: 203.0.113.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8
netplan apply

Debian (interfaces file)

nano /etc/network/interfaces
auto eth0
iface eth0 inet static
    address 203.0.113.10
    netmask 255.255.255.0
    gateway 203.0.113.1
    dns-nameservers 1.1.1.1 8.8.8.8
systemctl restart networking

CentOS/AlmaLinux (nmcli)

nmcli con mod eth0 ipv4.addresses 203.0.113.10/24
nmcli con mod eth0 ipv4.gateway 203.0.113.1
nmcli con mod eth0 ipv4.dns "1.1.1.1 8.8.8.8"
nmcli con mod eth0 ipv4.method manual
nmcli con up eth0

Verify the Configuration

ip addr show eth0
ping -c 3 8.8.8.8

Add a Secondary IP Address

# Temporary (lost on reboot):
ip addr add 203.0.113.11/24 dev eth0

# Permanent (add to Netplan under addresses):
addresses:
  - 203.0.113.10/24
  - 203.0.113.11/24
  • 0 Kasutajad peavad seda kasulikuks
Kas see vastus oli kasulik?

Seotud artiklid

Understanding Your Server's Network Configuration

Understanding Your Server's Network Configuration Knowing how to read and manage your server's...

Setting Up Reverse DNS (rDNS/PTR Record)

Setting Up Reverse DNS (rDNS / PTR Record) A reverse DNS (PTR) record maps your IP address back...

Setting Up Nginx as a Reverse Proxy

Setting Up Nginx as a Reverse Proxy A reverse proxy forwards incoming requests to a backend...

How to Configure DNS Records for Your Domain

Configuring DNS Records for Your Domain DNS records tell the internet how to reach your domain....

Setting Up a Mail Server with Postfix and Dovecot

Setting Up a Mail Server with Postfix and Dovecot This guide sets up a basic mail server: Postfix...