ubuntu 20.04的静态IP配置

修改配置IP地址对应参数即可
sudo vim /etc/netplan/01-network-manager-all.yml
network:
ethernets: #你当前的网卡名称;
ens192:
dhcp4: false· #ipv4接口的dhcp开关,false为关闭,true为开启
optional: true
addresses: [11.11.11.1/24] #静态IP地址/掩码
gateway4: 11.11.11.254 #ipv4网关
nameservers:
addresses: [114.114.114.114,8.8.8.8] #DNS服务器 逗号分割
version: 2

执行命令重启网络服务生效
sudo netplan apply

配置DNS
/etc/resolv.conf

———————————————————–
sudo vim /etc/netplan/01-network-manager-all.yml
network:
ethernets:
ens192:
dhcp4: false·
optional: true
addresses: [11.11.11.1/24]
gateway4: 11.11.11.254
nameservers:
addresses: [11.11.11.254,11.11.11.1]

执行命令重启网络服务生效
sudo netplan apply

Ubuntu 16.04 配置单网卡绑定多IP

一、单个网卡配置多个IP

root@ubuntu:~# vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0 //这台主机只有 eth0 这张网卡
iface eth0 inet static
address 11.11.11.1
netmask 255.255.255.0
gateway 11.11.11.254
dns-nameserver 11.11.11.254

auto eth0:0 //配置子ip eth0:0
iface eth0:0 inet static
address 11.11.11.2
netmask 255.255.255.0

auto eth0:1 //配置子ip eth0:1
iface eth0:1 inet static
address 11.11.11.3
netmask 255.255.255.0

auto eth0:2 //配置子ip eth0:2 ;接着可以依次类推
iface eth0:2 inet static
address 11.11.11.4
netmask 255.255.255.0

二、添加DNS
root@ubuntu:~# vim /etc/resolvconf/resolv.conf.d/head
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN
nameserver 11.11.11.254 # 添加这一行

三、刷新DNS
root@ubuntu:~# resolvconf -u

四、重新启动网络服务
systemctl restart networking

Ubuntu 16.04 配置IP

1、网络ip信息配置
vi /etc/network/interfaces
auto ens192
iface ens192 inet static # 静态ip,不采用DHCP动态分配
address 11.11.11.1 # 配置ip
netmask 255.255.255.0 # 子网掩码
gateway 11.11.11.254 # 网关

2、配置DNS
vi /etc/resolv.conf
nameserver 11.11.11.254

3、重新启动网络服务
systemctl network restart