# Debian网络配置
修改网络配置文件:/etc/network/interfaces
配置为DHCP:
auto enp0s3
allow-hotplug enp0s3
iface enp0s3 inet dhcp
1
2
3
2
3
配置为静态IP:
auto enp0s9
allow-hotplug enp0s9
iface enp0s9 inet static
address 192.168.1.10
netmask 255.255.255.0
gateway 192.168.1.1
1
2
3
4
5
6
2
3
4
5
6
注意点:
- auto 是在系统启动的时候启动网络接口,无论网络接口是否插入网线,都会去检查,比如配置了DHCP,则无论是否有网线,系统都会去执行DHCP。
- allow-hotplug 只有当内核从该接口检测到热插拔事件后才启动该接口,如果系统开机没有插入网线,则系统不会启动该接口,系统启动后,插入网线则会自动启动该接口。
# 常用命令
# 启动接口
ifup <interface_name>
# 关掉接口
ifdown <interface_name>
# 网络重启
/etc/init.d/networking restart
service networking restart
1
2
3
4
5
6
7
2
3
4
5
6
7
# Centos网络配置
Centos的网络配置路径为:/etc/sysconfig/network-scripts,注意默认情况下centos的网络并不是默认打开的,如果需要打开则需要把对应的ONBOOT改为yes。
如果要配置静态ip
ONBOOT=yes
BOOTPROTO=static
IPADDR="10.0.100.195"
NETMASK="255.255.255.0"
GATEWAY="10.0.100.1"
DNS1="114.114.114.114"
1
2
3
4
5
6
2
3
4
5
6