Debian/Ubuntu 网卡配置

请先停止 NetworkManager 这个搅屎棍

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
40
41
42
43
44
45
46
47
48
先临时设定ip,然后登陆上去
root@ubuntu:~# ifconfig eth0 10.11.12.2/24

root@raspberrypi:~# vim /etc/network/interfaces

#auto eth0
#allow-hotplug eth0
#iface eth0 inet manual

auto eth0
iface eth0 inet static
address 10.11.12.19
netmask 255.255.255.0
gateway 10.11.12.13
dns-nameservers 180.76.76.76 223.5.5.5



auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
root@raspberrypi:~#



重启网络
root@ubuntu:~# ifdown eth0 && ifup eth0

或者:
root@raspberrypi:~# /etc/init.d/networking restart


测试
root@raspberrypi:~# ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=1 ttl=57 time=2.76 ms
64 bytes from 115.239.210.27: icmp_seq=2 ttl=57 time=2.78 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 2.761/2.770/2.780/0.053 ms
root@raspberrypi:~#

Debian/Ubuntu 网卡别名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
root@localhost:~# cat /etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth0:A
iface eth0:A inet static
address 192.168.0.239
netmask 255.255.255.0

auto wlan0
iface wlan0 inet dhcp
wpa-ssid XXXXXXX
wpa-psk XXXXXXX

up route del -net 0.0.0.0/0 gw 192.168.20.1
up route add -net 0.0.0.0/0 gw 172.16.1.254
root@localhost:~#

Redhat/CentOS 配置网卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
临时修改网卡IP
ifconfig eth0 172..16.0.5/16 up

添加网关
route add default gw 172.16.0.111

vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=00:0C:29:36:**:**
TYPE=Ethernet
UUID=7eaffa26-ee97-4d23-a333-a84da8341***
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=172.16.0.103
NETMASK=255.255.255.0
GATEWAY=172.16.0.111
DNS1=114.114.114.114
DNS2=8.8.8.8

我的CentOS7网卡配置

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
40
41
[root@localhost network-scripts]# cat ifcfg-*

# 逻辑桥
供 KVM众多虚拟机使用, 供OpenVPN虚拟网络使用,
TYPE="Bridge"
BOOTPROTO="dhcp"
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
MACADDR=8C:89:A5:1D:FA:DC
DEVICE="br0"
ONBOOT="yes"

# 物理接口
# 搭在桥上, 让桥上的所有对象拥有 二层网络寻址功能
TYPE="Ethernet"
BOOTPROTO=manual
NAME="em1"
DEVICE="em1"
UUID="3a67e7d9-3ba7-486a-b9be-6f51c5243bc0"
IPV4_FAILURE_FATAL=no
ONBOOT="yes"
BRIDGE=br0
ETHTOOL_OPTS="speed 1000 duplex full autoneg off"


# 逻辑接口,TAP 类型, 搭到桥上
TYPE="Tap"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="none"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
NAME="tap0"
MACADDR=AB:89:AB:1D:AB:DC
DEVICE="tap0"
ONBOOT="yes"
BRIDGE=br0

[root@localhost network-scripts]#