怎麼配置eth2網卡
1. LINUX伺服器雙網卡設置問題
linux系統配置雙網卡:$>./ifconfigeth1Linkencap:EthernetHWaddr00:13:46:77:48:ACinetaddr:219.148.64.28Bcast:219.148.64.255Mask:255.255.255.192inet6addr:fe80::213:46ff:fe77:48ac/64Scope::1500Metric:1RXpackets:5486793errors:0dropped:0overruns:0frame:0TXpackets:4236830errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:1000RXbytes:888757239(847.5Mb)TXbytes:2411899947(2300.1Mb)Interrupt:177Baseaddress:0xc400eth2Linkencap:EthernetHWaddr00:04:23:BC:B0:EEinetaddr:192.168.188.108Bcast:192.168.188.255Mask:255.255.255.0inet6addr:fe80::204:23ff:febc:b0ee/64Scope::1500Metric:1RXpackets:5716903errors:0dropped:0overruns:0frame:0TXpackets:5108832errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:1000RXbytes:2507878307(2391.6Mb)TXbytes:883953795(843.0Mb)Baseaddress:0xbc00Memory:fc5e0000-fc600000eth2:0Linkencap:EthernetHWaddr00:04:23:BC:B0:EEinetaddr:192.168.109.3Bcast:192.168.109.255Mask:255.255.255.:1500Metric:1Baseaddress:0xbc00Memory:fc5e0000-fc600000路由配置如下:$>./route-9.148.64.00.0.0.0255.255.255.192U000eth1192.168.118.0219.148.64.1255.255.255.0UG000eth1192.168.109.00.0.0.0255.255.255.0U000eth2192.168.188.00.0.0.0255.255.255.0U000eth2127.0.0.00.0.0.0255.0.0.0U000lo0.0.0.0219.148.64.10.0.0.0UG000eth1
2. linux設置雙網卡
設置網關就是和這個本幾同網段的是出口的那IP
3. Linux系統雙網卡綁定配置教程
系統版本
[root@ ~]# cat /etc/redhat-release
CentOS release 6.8 (Final)
[root@ ~]# uname -r
2.6.32-642.6.1.el6.x86_64
網卡說明
eth0 192.168.1.8(伺服器外網卡)
eth1 伺服器網卡(內網)
eth2 伺服器網卡(內網)
[root@ ~]# /etc/init.d/iptables stop
[root@ ~]# chkconfig iptables off
關閉selinux
[root@ ~]#setenforce 0
[root@ ~]#sed -i 『s/SELINUX=enforcing/SELINUX=disabled/『 /etc/selinux/config
禁用NetworkManager
[root@ ~]# /etc/init.d/NetworkManager stop
Stopping NetworkManager daemon: [ OK ]
[root@ ~]# chkconfig NetworkManager off
[root@ ~]# /etc/init.d/network restart
雙網卡綁定配置過程
[root@ ~]# cd /etc/sysconfig/network-scripts/
編輯eth1網卡
[root@ network-scripts]# cat >ifcfg-eth1 <> DEVICE=eth1
> ONBOOT=yes
> BOOTPROTO=none
> USERCTL=no
> MASTER=bind0
> EOF
編輯eth2網卡
[root@ network-scripts]# cat >ifcfg-eth2
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bind0
EOF
編輯bind0網卡
[root@ network-scripts]# cat >ifcfg-bind0 <> DEVICE=bind0
> TYPE=Ethernet
> ONBOOT=yes
> BOOTPROTO=none
> IPADDR=10.0.0.8
> NETMASK=255.255.255.0
> GATEWAY=10.0.0.254
> IPV6INIT=no
> USERCTL=no
> EOF
配置bond參數
[root@ network-scripts]# cat >/etc/modprobe.conf <> alias bind0 bonding
> options bind0 miimon=100 mode=6
> EOF
加入開機自啟動(/etc/rc.local)
[root@ network-scripts]# cat >>/etc/rc.local <> ifenslave bind0 eth1 eth2
> EOF
重啟網路服務
[root@LVS-2 network-scripts]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth1: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bind0: WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
Determining if ip address 10.0.0.8 is already in use for device bind0..[ OK ]
Bringing up interface eth0: Determining if ip address 192.168.1.8 is already in use for device eth0... [ OK ]
Bringing up interface eth1: RTNETLINK answers: File exists [ OK ]
Bringing up interface eth2: RTNETLINK answers: File exists [ OK ]
配置使綁定立即生效
[root@LVS-2 network-scripts]# ifenslave bind0 eth1 eth2
測試聯通
[root@LVS-2 network-scripts]# ping 10.0.0.8
PING 10.0.0.8 (10.0.0.8) 56(84) bytes of data.
64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=0.089 ms
64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.046 ms
^C
--- 10.0.0.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1921ms
rtt min/avg/max/mdev = 0.046/0.067/0.089/0.023 ms
此時會發現系統多一個網卡
[root@LVS-2 network-scripts]# ifconfig bind0
bind0
Link encap:Ethernet HWaddr 00:0C:29:CC:9B:5
inet addr:10.0.0.8 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fecc:9b55/64 Scope:LinkUP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:151 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:11826 (11.5 KiB) TX bytes:258 (258.0 b)
4. 3.ubuntu server的網卡綁定和橋接
為了方便做這個實驗,我在虛擬機上配置了4塊網卡,其中eth0和eth1配置為NAT模式,eth2和eth3配置為「僅主機模式」。eth0和eth1可以通過NAT轉換連接外網,網段為192.168.36.X,eth2和eth3不能連接外網網段為172.16.22.X。創建網橋之前要先安裝bridge-utils: sudo apt install bridge-utils 。網卡配置如下:
只給eth0配置一個地址,配置文件如下:
修改配置文件後,執行 sudo netplan apply 使配置生效,此時網路配置如下:
把eth0和eth2配置上靜態IP,配置文件如下:
執行 sudo netplan apply 後,兩個網卡的網路都是通的,網路配置如下
創建一個網橋br0,然後將br0橋接到eth0上。配置文件如下:
執行 sudo netplan apply 後,兩個網卡的網路都是通的,網路配置如下(修改網橋配置後,有時執行 sudo netplan apply 後網路不通,需要重啟伺服器)
創建兩個網橋br0和br1,然後分別橋接到eth0和eth2上。配置文件如下:
測試兩個網段的網路,都是通的。
網卡綁定共有7中模式,概念如下:
測試網路,沒有問題。
⽹卡綁定⽤於提供⽹卡接⼝冗餘以及⾼可⽤和端⼝聚合功能,橋接⽹卡再給需要橋接設備的服務使⽤。將網卡eth0和eth1綁定為bond0,再創建一個網橋br0,與bond0橋接。配置文件如下:
測試網路,沒有問題
把eth0和eth1綁定為bond0,連接NAT網路,通過共享主機網路上網模擬外網;eth2和eth3綁定為bond1,連接僅主機網路模擬內網。配置文件如下:
測試網路:
把eth0和eth1綁定為bond0,連接NAT網路,通過共享主機網路上網模擬外網;eth2和eth3綁定為bond1,連接僅主機網路模擬內網,創建網橋br0和br1,並分別橋接到bond0和bond1上。配置文件如下:
測試網路:
總結:以上就是ubuntu1804網卡靜態IP地址、bond、橋接、bond+橋接的配置方式。查看網路可以用 ifconfig 命令,當前哪個模式的網卡(網橋、bond)工作,哪個模式的網卡(網橋、bond)就會顯示有IP地址。通過配置文件或有IP地址的設備都可以確定網卡的工作模式。
5. 虛擬機linux添加的新網卡沒有發現其配置文件eth1和eth2。
首先,有沒有發現這個配置文件都沒有什麼所謂的,先查看vi /etc/udev/rules.d/70-persistent-net.rules這里能看到你的網卡信息,找到你對應網卡的NAME;例如:SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR=="00:0c:29:8f:89:97", ATTR=="1", KERNEL=="eth*", NAME="eth0"這里網卡名定義為eth0;然後vi /etc/sysconfig/network-sprict/ifcfg-eth0 新建並編輯這個網卡配置文件,名字其實隨意。內容DEVICE=eth0 對應上面找到的網卡名,這個是關鍵,其他的按照默認的設置就可以了設置完之後重啟下服務即可識別使用了,跟你說一件事吧,在VM裡面,你添加了網卡,就算使用了 ifconfig -a也有時候查看不到任何網卡的,但是你的網卡又確實存在,另外你是感興趣的話可以看下劉遄老師寫的《Linux就該這么學》作為入門的書籍,覺得不錯的話採納下哦~
6. 在linux系統下如何配置雙網卡
你這個需求,需要使用iproute2包中的 ip命令完成。
首先 /etc/iproute2/rt_tables 裡面添加2個table, 對應2個不同的網段(net3 net5)
配置思路是 用ip route 命令為net3 table增加default gw 118.126.3.1,net5 table 增加default gw 118.126.5.1
然後用 ip rule 命令 使用源地址匹配規則 源地址為118.126.3.16的數據包選擇 net3 table, 源地址為118.126.5.251的數據包選擇net5 table.
當然你也需要設置本機的默認default gw(直接用route命令),那麼由本機生成的數據包,默認會選用與default gw連接的那塊網卡的ip地址對外通訊(程序指定的除外)。
以上配置對於正常開發的 tcp通訊軟體完全可以正確工作,ping也沒有問題。 不過某些開發不正確的udp軟體可能運行會不正常(這種udp軟體,在有兩個以上ip地址的主機上工作都會有問題)
7. 虛擬機linux添加的新網卡沒有發現其配置文件eth1和eth2。
首先,有沒有發現這個配置文件都沒有什麼所謂的
先查看vi /etc/udev/rules.d/70-persistent-net.rules
這里能看到你的網卡信息,找到你對應網卡的NAME
例如
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:8f:89:9
7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
這里網卡名定義為eth0
然後vi /etc/sysconfig/network-sprict/ifcfg-eth0 新建並編輯這個網卡配置文件,名字其實隨意
內容
DEVICE=eth0 對應上面找到的網卡名,這個是關鍵,其他的按照默認的設置就可以了
設置完之後重啟下服務即可識別使用了
跟你說一件事吧,在VM裡面,你添加了網卡,就算使用了 ifconfig -a也有時候查看不到任何網卡的,但是你的網卡又確實存在。。。。
8. 怎樣改變eth0,eth1,eth2,eth3所對應的物理網卡
你好, AC地址也叫物理地址、硬體地址或鏈路地址,由網路設備製造商生產時寫在硬體內部。IP地址與MAC地址在計算機里都是以二進製表示的,IP地址是32位的,而MAC地址則是48位的。MAC地址的長度為48位(6個位元組),通常表示為12個16進制數,每2個16進制數之間用冒號隔開,如:08:00:20:0A:8C:6D就是一個MAC地址,其中前6位16進制數08:00:20代表網路硬體製造商的編號,它由IEEE(電氣與電子工程師協會)分配,而後3位16進制數0A:8C:6D代表該製造商所製造的某個網路產品(如網卡)的系列號。只要你不去更改自己的MAC地址,那麼你的MAC地址在世界是惟一的。
希望能幫到你。