title:centos ubuntu debian with netwoks
一、Debian10网卡配置
1
| nano /etc/network/interfaces
|
1 2 3 4 5 6 7 8 9 10
| # 多IP配置 auto eno1 iface eno1 inet static address 192.168.10.1/24 gateway 192.168.10.254 dns-nameservers 8.8.8.8 auto eno1:0 iface eno1:0 inet static address 192.168.10.2/24
|
nano使用
1 2 3
| ctrl+o #保存配置 ctrl+x #退出
|
#debian重启网卡命令
1 2 3
| systemctl restart networking /etc/init.d/networking restart service networking restart
|
二、Debian7/8/9网卡配置
1
| nano /etc/network/interface
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| #网卡配置多IP ``` auto lo iface lo inet loopback
auto eth0 iface eth0 inet static address 192.168.10.1 netmask 255.255.255.0 gateway 192.168.10.254 dns-nameservers 8.8.8.8 auto eth0:0 address 192.168.10.2 netmask 255.255.255.0
|
ctrl+o #保存配置 + 回车
ctrl+x #退出
1 2 3 4
| #下面三条命令都可以使用 systemctl restart networking /etc/init.d/networking restart service networking restart
|
三、ubuntu16/ubuntu17网卡配置
1
| vi /etc/network/interfaces
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| auto eno1 iface eno1 inet static address 10.0.0.0 netmask 255.255.255.0 gateway 10.0.0.254 dns-nameservers 8.8.8.8 auto eno1:0 #第二个IP iface eno1:0 inet static address 10.0.0.0 netmask 255.255.255.0 auto eno1:1 #第三个,更多以此类推 iface eno1:1 inet static address 10.0.0.0 netmask 255.255.255.0
|
重启网卡
1 2 3 4 5
| /etc/init.d/networking restart 或指定启动关闭某个网卡命令 ifdown enp0s3 (关闭网卡enp0s3) ifup enp0s3 (启动网卡enp0s3) service network-manager restart
|
四、ubuntu18-ubuntu20网卡配置
1
| vi /etc/netplan/** ##默认01/00数字开头文件
|
此版本对配置文件格式要求严格,错一步就会导致整张网卡报错
1 2 3 4 5 6 7 8 9 10 11
| network: version: 2 renderer: networkd ethernets: eno1: addresses: [ 172.25.1.1/24,172.25.1.2/24 ] gateway4: 172.25.1.254 nameservers: addresses: [ 8.8.8.8,114.114.114.114 ] eno2: addresses: [ 192.168.1.1/24 ]
|
重启网卡
1 2 3 4 5
| netplan apply
ifconfig eth0 down
ifconfig eth0 up #eth0指网卡名
|
五、Centos7/8网卡配置
vi /etc/sysconfig/network-scripts/ifcfg-eno1 #(ifcfg-网卡名)
1 2 3 4 5 6 7 8 9 10
| BOOTPROTO=static DEVICE=eno1 ONBOOT=yes IPADDR=10.10.0.0 Netmask=255.255.255.0 #IPADDR1=10.10.0.1 #Netmask1=255.255.255.0 GATEWAY=10.10.0.254 DNS1=8.8.8.8 DNS2=114.114.114.114
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| #centos7 重启网卡 #命令1 /etc/init.d/network restart #命令2 systemctl restart network
#centos8重启网卡 nmcli connection reload
#不能立即生效的命令 nmcli d c eno1
nmcli c r eno1
nmcli d r eno1
#一次运行 nmcli d c eno1&&nmcli c r eno1&&nmcli d r eno1
|
重启失败,检查网卡配置文件内容,如无误,centos6建议直接重启,centos7一般是NetworkManager服务限制了,可以关闭服务重试
1
| systemctl stop NetworkManager && systemctl restart network && sleep 5s && systemctl start NetworkManager
|
NetworkManager服务开启也可以用nmtui
命令进入图形界面配置网卡
More info: Deployment