0 1011
linux 静态网络配置大全(包括ubuntu centos Debian等等)_图一
Insert title here

这里介绍最新的ubuntu版本和最新的centos版本等常用的服务器网络配置。

注:一般外网服务器上的网络采用的 enp1s0 方式多一点,如果你是本地的虚拟机配置一般用 ens33方式,还得把虚拟机的网络适配器改成桥接模式。

具体服务器配置如下:



Ubuntu 17.10, Ubuntu 18.xx, Ubuntu 19.xx, Ubuntu 20.xx

Populate the /etc/netplan/10-ens3.yaml file with the following text.
network:
  version: 2
  renderer: networkd
  ethernets:
    enp1s0:
      dhcp4: no
      addresses: [192.168.2.116/24]
      gateway4: 192.168.2.100
      nameservers:
        addresses: [114.114.114.114]
      routes:
      - to: 169.254.0.0/16
        via: 192.168.2.100
        metric: 100
Update networking or reboot.
netplan apply

Ubuntu 16.xx, Ubuntu 17.04

Populate the /etc/network/interfaces file with the following text.
auto lo
iface lo inet loopback

auto enp1s0
iface enp1s0 inet static
	address 192.168.2.116
	netmask 255.255.255.0
	gateway 192.168.2.100
	dns-nameservers 114.114.114.114
	post-up ip route add 169.254.0.0/16 dev enp1s0


Start each interface or reboot the system.
ifup enp1s0

Ubuntu 12.xx - Ubuntu 15.xx

Populate the /etc/network/interfaces file with the following text.
auto lo
iface lo inet loopback

auto enp1s0
iface enp1s0 inet static
	address 192.168.2.116
	netmask 255.255.255.0
	gateway 192.168.2.100
	dns-nameservers 114.114.114.114
	post-up ip route add 169.254.0.0/16 dev enp1s0


Start each interface or reboot the system.
ifup eth0

CentOS 6

Populate the /etc/sysconfig/network-scripts/ifcfg-enp1s0 file with the following text.
DEVICE=enp1s0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.2.116
NETMASK=255.255.255.0
GATEWAY=192.168.2.100
DNS1=114.114.114.114

Populate the /etc/sysconfig/network-scripts/route-enp1s0 file with the following text.
169.254.0.0/16 dev enp1s0
Restart networking or reboot.
service network restart

CentOS 7

Populate the /etc/sysconfig/network-scripts/ifcfg-eth0 file with the following text.
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.2.116
NETMASK=255.255.255.0
GATEWAY=192.168.2.100
DNS1=114.114.114.114

Populate the /etc/sysconfig/network-scripts/route-eth0 file with the following text.
169.254.0.0/16 dev eth0
Restart networking or reboot.
service network restart

CentOS 8

Populate the /etc/sysconfig/network-scripts/ifcfg-enp1s0 file with the following text.
TYPE="Ethernet"
DEVICE="enp1s0"
ONBOOT="yes"
BOOTPROTO="none"
IPADDR=192.168.2.116
PREFIX=24
GATEWAY=192.168.2.100
DNS1=114.114.114.114
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
Restart the connection, or reboot.
nmcli con load /etc/sysconfig/network-scripts/ifcfg-enp1s0
nmcli con up 'System enp1s0'

Debian 7, Debian 8

Populate the /etc/network/interfaces file with the following text.
auto lo
iface lo inet loopback

auto enp1s0
iface enp1s0 inet static
	address 192.168.2.116
	netmask 255.255.255.0
	gateway 192.168.2.100
	dns-nameservers 114.114.114.114
	post-up ip route add 169.254.0.0/16 dev enp1s0


Restart networking or reboot.
systemctl restart networking.service

Debian 9, Debian 10

Populate the /etc/network/interfaces file with the following text.
auto lo
iface lo inet loopback

auto enp1s0
iface enp1s0 inet static
	address 192.168.2.116
	netmask 255.255.255.0
	gateway 192.168.2.100
	dns-nameservers 114.114.114.114
	post-up ip route add 169.254.0.0/16 dev enp1s0


Restart networking or reboot.
systemctl restart networking.service

Fedora 24 - 28

Populate the /etc/sysconfig/network-scripts/ifcfg-enp1s0 file with the following text.
DEVICE=enp1s0
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
NOZEROCONF=yes
IPADDR=192.168.2.116
NETMASK=255.255.255.0
GATEWAY=192.168.2.100
DNS1=114.114.114.114

Populate the /etc/sysconfig/network-scripts/route-enp1s0 file with the following text.
169.254.0.0/16 dev enp1s0
Restart networking or reboot.
systemctl restart network.service

Fedora 29 - 31

Run the following commands to configure the public network.
nmcli con add con-name public-net ifname enp1s0 type ethernet ipv4.method 'manual' ipv4.addresses '192.168.2.116/24' ipv4.gateway '192.168.2.100' ipv4.dns ''
nmcli con mod public-net +ipv4.dns '114.114.114.114'


FreeBSD 10.x, FreeBSD 11.x, FreeBSD 12.x

Populate the /etc/rc.conf file with the following text.
static_routes="linklocal"
route_linklocal="-net 169.254.0.0/16 -interface vtnet0"
ifconfig_vtnet0="inet 192.168.2.116 netmask 255.255.255.0"
defaultrouter="192.168.2.100"


Reboot the system.
reboot

OpenBSD 6.0 - OpenBSD 6.2

Populate the /etc/mygate file with the following text.
192.168.2.100
Populate the /etc/hostname.vio0 file with the following text.
inet 192.168.2.116 255.255.255.0 NONE
Populate the /etc/resolv.conf file with the following text.
nameserver 114.114.114.114
lookup file bind
Reboot the system.
reboot

OpenBSD 6.3 - OpenBSD 6.8

Populate the /etc/mygate file with the following text.
192.168.2.100
Populate the /etc/hostname.vio0 file with the following text.
inet 192.168.2.116 255.255.255.0 NONE
Populate the /etc/resolv.conf file with the following text.
nameserver 114.114.114.114
lookup file bind
Reboot the system.
reboot

OpenBSD 6.9

Populate the /etc/mygate file with the following text.
192.168.2.100
Populate the /etc/hostname.vio0 file with the following text.
inet 192.168.2.116 255.255.255.0 NONE
Populate the /etc/resolv.conf file with the following text.
nameserver 114.114.114.114
lookup file bind
Reboot the system.
reboot


[分类]
[来源] http://erlangyun.com/p/id/227.html
[声明] 本站资源来自用户分享,如损害你的权益请联系客服QQ:120074275给予处理。