Linux设置静态IP

ArchLinux

​ 1.编辑配置文件

​ 网卡

1
/etc/dhcpcd.conf

​ 2.添加下列内容

1
2
3
4
interface eth0						#设置网卡名
static ip_address=10.0.0.10/24 #设置IP和掩码位
static routers=10.0.0.1 #设置网关
static domain_name_servers=10.0.0.1 #设置DNS

​ 3.常用命令

1
2
systemctl status systemd-networkd			#查看网络状态
systemctl restart dhcpcd #重启DHCP

CentOS

​ 1.编辑配置文件

1
/etc/sysconfig/network-scripts

​ 2.清空内容并添加以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0" #网卡名称
UUID="5ee00e18-1161-4c0b-b874-1931dbd7ea33" #ID
DEVICE="eth0"
ONBOOT="yes"
IPADDR="10.0.0.132" #静态IP地址
PREFIX="28" #掩码位
GATEWAY="10.0.0.128" #子网掩码
DNS1="10.0.0.128" #DNS


Debian

​ 1.编辑配置文件

1
/etc/network/interfaces

​ 2.清空内容并添加以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
auto eth0						#设置网卡名

iface eth0 inet static
address 10.0.0.9 #设置IP和掩码位
netmask 255.255.255.0 #设置子网掩码
gateway 10.0.0.1 #设置网关


auto eth0 eth1

iface eth0 inet static
address 10.0.0.10
netmask 255.255.255.0
gateway 10.0.0.1
dns-nameservers 10.0.0.1

iface eth1 inet static
address 10.0.1.10
netmask 255.255.255.0
gateway 10.0.1.1

armbian
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
source /etc/network/interfaces.d/*

# Network is managed by Network manager
# You can choose one of the following two IP setting methods:
# Use # to disable another setting method


# 01. Enable dynamic DHCP to assign IP
#auto eth0
#iface eth0 inet dhcp
hwaddress ether mac


# 02. Enable static IP settings(IP is modified according to the actual)
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 10.0.0.1
netmask 255.255.255.0
gateway 10.0.0.1
dns-nameservers 119.29.29.29
dns-nameservers 10.0.0.1


# 03. Docker install OpenWrt and communicate with each other
#allow-hotplug eth0
#no-auto-down eth0
#auto eth0
#iface eth0 inet manual
#
#auto macvlan
#iface macvlan inet dhcp
# hwaddress ether mac
# pre-up ip link add macvlan link eth0 type macvlan mode bridge
# post-down ip link del macvlan link eth0 type macvlan mode bridge
#
#auto lo
#iface lo inet loopback


Ubuntu

​ 1.编辑配置文件

1
/etc/netplan/********.yaml				#*填写对应的名称

​ 2.修改内容为如下,本设置为双网卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
network:
ethernets:
eth0: #网卡名称
dhcp4: false
addresses: [10.0.0.11/24] #IP和掩码位
routes:
- to: 0.0.0.0/0
via: 10.0.0.1
metric: 30 #优先级
optional: true
nameservers:
     addresses: [10.0.0.1,119.29.29.29] #DNS

eth1:
dhcp4: false
addresses: [10.0.0.131/28]
routes:
- to: 0.0.0.0/0
via: 10.0.0.128
metric: 20
optional: true
nameservers:
     addresses: [10.0.0.128]
version: 2

​ 3.重启网卡并

1
netplan apply

Linux设置静态IP
https://kuan.pages.dev/article/ef9375d1.html
作者
IKun
发布于
2023年1月25日
许可协议