您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“rhel6.5中雙網(wǎng)卡雙網(wǎng)關(guān)如何配置”,內(nèi)容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“rhel6.5中雙網(wǎng)卡雙網(wǎng)關(guān)如何配置”這篇文章吧。
服務(wù)器環(huán)境如下:
系統(tǒng):RHEL6.5
電信IP(TEL):114.80.10.79 netmask 255.255.255.128 gateway 114.80.10.1
聯(lián)通IP(CNC):112.65.20.23 netmask 255.255.255.128 gateway 112.65.20.1
1、配置網(wǎng)卡信息
vi /etc/sysconfig/network-scripts/ifcfg-eth22
DEVICE=eth22
HWADDR=00:90:FA:76:A5:BC
TYPE=Ethernet
UUID=ebd54026-4412-4cc3-9f74-e065d4328072
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=114.80.10.79
NETMASK=255.255.255.128
vi /etc/sysconfig/network-scripts/ifcfg-eth24
DEVICE=eth24
HWADDR=00:90:FA:76:A5:98
TYPE=Ethernet
UUID=ebd54026-4412-4cc3-9f74-e065d4328479
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=112.65.20.23
NETMASK=255.255.255.128
注意:兩個(gè)網(wǎng)卡配置文件里不加網(wǎng)關(guān).如果加網(wǎng)關(guān),那么在route -n中只會(huì)顯示一條默認(rèn)路由,另一個(gè)網(wǎng)段是不通的。
[root@test network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
112.65.20.0 0.0.0.0 255.255.255.128 U 0 0 0 eth24
114.80.10.0 0.0.0.0 255.255.255.128 U 0 0 0 eth22
112.65.20.0 0.0.0.0 255.255.255.0 U 0 0 0 eth24
114.80.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth22
169.254.0.0 0.0.0.0 255.255.0.0 U 1016 0 0 eth24
169.254.0.0 0.0.0.0 255.255.0.0 U 1016 0 0 eth22
0.0.0.0 112.65.20.1 255.255.255.128 UG 0 0 0 eth24
2、修改rc.local
可以直接增加這兩條路由,但是重啟后會(huì)丟失。
route add -net 114.80.10.0/25 gw 114.80.10.1 dev eth22
route add -net 112.65.20.0/25 gw 112.65.20.1 dev eth24
所以為永久生效,還是修改rc.local
vi /etc/rc.d/rc.local
[root@test network-scripts]# cat /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
route add -net 114.80.10.0/25 gw 114.80.10.1 dev eth22
route add -net 112.65.20.0/25 gw 112.65.20.1 dev eth24
然后route -n
[root@test network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
112.65.20.0 112.65.20.1 255.255.255.128 UG 0 0 0 eth24
114.80.10.0 114.80.10.1 255.255.255.128 UG 0 0 0 eth22
112.65.20.0 0.0.0.0 255.255.255.0 U 0 0 0 eth24
114.80.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth22
169.254.0.0 0.0.0.0 255.255.0.0 U 1016 0 0 eth24
169.254.0.0 0.0.0.0 255.255.0.0 U 1016 0 0 eth22
(如果只需要添加默認(rèn)路由可以這樣設(shè)置:
route add default gw 112.65.20.1
route del default gw 112.65.20.1 (可以刪除默認(rèn)路由,用此方法改變后幾分鐘就可以生效.)
還有另外一種方法就是通過策略性路由配置iproute2工具包來實(shí)現(xiàn)。這個(gè)軟件包是由Alexey Kuznetsov開發(fā)的,軟件包所在的主要網(wǎng)址為ftp://ftp.inr.ac.ru/ip-routing/。
1.增加2個(gè)路由表分別是電信:tel 聯(lián)通:cnc
# vi /etc/iproute2/rt_tables
252 tel
251 cnc
保存并推出
2.增加路由規(guī)則
# ip route flush table tel
# ip route add default via 114.80.10.1 dev eth22 src 114.80.10.4 table tel
# ip ruleadd from 114.80.10.4 table tel
此處是設(shè)置電信的網(wǎng)關(guān),并可實(shí)現(xiàn)讓電信的資源訪問只從eth22網(wǎng)卡出去
# ip route flush table cnc
# ip route add default via 112.65.20.1 dev eth24 src 112.65.20.2 table cnc
# ip rule add from 112.65.20.2 table cnc
此處是設(shè)置聯(lián)通的網(wǎng)關(guān),并可實(shí)現(xiàn)讓聯(lián)通的資源訪問只從eth24網(wǎng)卡出去
3.配置network啟動(dòng)腳本文件 在結(jié)尾之前增加如下內(nèi)容
# vi /etc/rc.d/init.d/network
ip route flush table tel
ip route add default via 114.80.10.1 dev eth22 src 114.80.10.4 table tel
ip rule add from 114.80.10.4 table tel
ip route flush table cnc
ip route add default via 112.65.20.1 dev eth24 src 112.65.20.2 table cnc
ip rule add from 112.65.20.2 table cnc
exit 0
5,退出并重啟網(wǎng)絡(luò)
# /etc/rc.d/init.d/network restart
此時(shí)再測試機(jī)器網(wǎng)絡(luò)情況,就會(huì)發(fā)現(xiàn)電信和聯(lián)通的地址都可以正常訪問了。此方法還可以實(shí)現(xiàn)讓從電信IP過來的請(qǐng)求按照電信路由返回,從網(wǎng)通IP過來的請(qǐng)求從網(wǎng)通路由返回。
6,服務(wù)器重啟,上述的路由規(guī)則就失效了,所以你需要把上面這段命令寫入系統(tǒng)啟動(dòng)腳本
RedHat/CentOS,系統(tǒng)啟動(dòng)腳本是/etc/rc.d/rc.local
以上是“rhel6.5中雙網(wǎng)卡雙網(wǎng)關(guān)如何配置”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。