久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

rhel6.5中雙網卡雙網關如何配置

190次閱讀
沒有評論

共計 3393 個字符,預計需要花費 9 分鐘才能閱讀完成。

這篇文章主要為大家展示了“rhel6.5 中雙網卡雙網關如何配置”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓丸趣 TV 小編帶領大家一起研究并學習一下“rhel6.5 中雙網卡雙網關如何配置”這篇文章吧。

服務器環境如下:

系統:RHEL6.5

電信 IP(TEL):114.80.10.79 netmask 255.255.255.128 gateway 114.80.10.1

聯通 IP(CNC):112.65.20.23 netmask 255.255.255.128 gateway 112.65.20.1

1、配置網卡信息

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

注意:兩個網卡配置文件里不加網關. 如果加網關,那么在 route - n 中只會顯示一條默認路由,另一個網段是不通的。

[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

可以直接增加這兩條路由,但是重啟后會丟失。

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

(如果只需要添加默認路由可以這樣設置:
route add default gw 112.65.20.1
route del default gw 112.65.20.1 (可以刪除默認路由,用此方法改變后幾分鐘就可以生效.)

還有另外一種方法就是通過策略性路由配置 iproute2 工具包來實現。這個軟件包是由 Alexey Kuznetsov 開發的,軟件包所在的主要網址為 ftp://ftp.inr.ac.ru/ip-routing/。

1. 增加 2 個路由表分別是電信:tel 聯通:cnc 

# vi /etc/iproute2/rt_tables 
252 tel 
251 cnc

保存并推出

2. 增加路由規則  
# 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

此處是設置電信的網關,并可實現讓電信的資源訪問只從 eth22 網卡出去

# 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

此處是設置聯通的網關,并可實現讓聯通的資源訪問只從 eth24 網卡出去

3. 配置 network 啟動腳本文件 在結尾之前增加如下內容

# 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,退出并重啟網絡

# /etc/rc.d/init.d/network restart

此時再測試機器網絡情況,就會發現電信和聯通的地址都可以正常訪問了。此方法還可以實現讓從電信 IP 過來的請求按照電信路由返回,從網通 IP 過來的請求從網通路由返回。

6,服務器重啟,上述的路由規則就失效了,所以你需要把上面這段命令寫入系統啟動腳本

RedHat/CentOS,系統啟動腳本是 /etc/rc.d/rc.local

以上是“rhel6.5 中雙網卡雙網關如何配置”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注丸趣 TV 行業資訊頻道!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-08-25發表,共計3393字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 和硕县| 长沙县| 梧州市| 衡南县| 昆山市| 肇州县| 宁国市| 扶余县| 伊川县| 蒙城县| 九台市| 隆德县| 沙雅县| 平南县| 酉阳| 蓝田县| 武隆县| 肇州县| 定安县| 北川| 姜堰市| 新郑市| 凤庆县| 邯郸县| 京山县| 读书| 绥芬河市| 金溪县| 盐津县| 陇川县| 凤山市| 宝鸡市| 通江县| 兴宁市| 上栗县| 文成县| 哈巴河县| 永昌县| 雷州市| 桦南县| 乌鲁木齐县|