route指令執行個體練習
第1章 指令配置
虛拟伺服器 | 網卡配置資訊 | 虛拟網卡名稱 | 虛拟網卡模式 |
伺服器01 | eth1 | 10.0.0.10/24 | nat模式 |
伺服器02 | eth2 | 10.0.0.11/24 | |
eth3 | 10.0.1.11/24 | 主機模式 | |
伺服器03 | 10.0.1.10/24 |
1.1 檢視三台主機的路由表
1.1.1 伺服器01
[root@route-01 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth1
0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth1
1.1.2 伺服器02
[root@route-02 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth2
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth3
0.0.0.0 10.0.1.254 0.0.0.0 UG 0 0 0 eth3
1.1.3 伺服器03
[root@route-03 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth2
0.0.0.0 10.0.1.254 0.0.0.0 UG 0 0 0 eth2
1.2 伺服器主機配置
1.2.1 伺服器01配置路由資訊
[root@route-01 ~]# route add -net 10.0.1.0/24 gw 10.0.0.11
[root@route-01 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
10.0.1.0 10.0.0.11 255.255.255.0 UG 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth1
0.0.0.0 10.0.0.254 0.0.0.0 UG 0 0 0 eth1
# 說明:利用添加網絡路由條目指令,在伺服器01上正确添加上一條去往10.0.1.0 網段的路由條目
1.2.2 伺服器03上配置網絡路由條目
[root@route-03 ~]# route add -net 10.0.0.0/24 gw 10.0.1.11
[root@route-03 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 10.0.1.11 255.255.255.0 UG 0 0 0 eth2
10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth2
0.0.0.0 10.0.1.254 0.0.0.0 UG 0 0 0 eth2
說明:利用添加網絡路由條目指令,在伺服器03上正确添加上一條去往10.0.0.0網段條目
1.2.3 在伺服器02 上開啟路由轉發
伺服器02主機在拓撲中負責進行路由轉發,需要開啟相關參數。
[root@route-02 ~]# vim /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
#
# Use '/sbin/sysctl -a' to list all possible parameters.
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
1.2.3.1 顯示轉發資訊
[root@route-02 ~]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
1.3 虛拟主機路由通路驗證
1.3.1 在伺服器01 上驗證
[root@route-01 ~]# traceroute 10.0.1.10
traceroute to 10.0.1.10 (10.0.1.10), 30 hops max, 60 byte packets
1 10.0.0.11 (10.0.0.11) 0.252 ms 0.231 ms 0.199 ms
2 10.0.1.10 (10.0.1.10) 0.999 ms !X 0.970 ms !X 0.940 ms !X
# 說明:通過 traceroute 路由路徑追蹤指令,已确認路由走向符合配置需求,即路由配置正确無誤。
# !X 表示已經完成路由追蹤過程。
1.3.2 伺服器03上進行驗證
[root@route-03 ~]# traceroute 10.0.0.10
traceroute to 10.0.0.10 (10.0.0.10), 30 hops max, 60 byte packets
1 10.0.1.11 (10.0.1.11) 0.287 ms 0.209 ms 0.176 ms
2 10.0.0.10 (10.0.0.10) 0.469 ms !X 0.526 ms !X 0.498 ms !X
#說明:通過 traceroute 路由路徑追蹤指令,已确認路由走向符合配置需求,即路由配置正确無誤。
# !X 表示已經完成路由追蹤過程。
第2章 linux 路由部署項目結論
整體配置部署步驟已符合原有項目需求,生産環境中,已經可以滿足 3 台伺服器主機在正常通路外網的同時,可以利用伺服器路由轉發功能與伺服器網路路由配置,實作内網環境跨網段進行通訊需求。
2.1 linux 路由部署異常分析
2.1.1 防火牆異常問題
伺服器主機 02 起到路由轉發功能,類似于路由器的角色,是以伺服器上防火牆功能需要關閉,否則防火牆相應條目會阻止掉路由轉發流量。
2.1.2 虛拟網卡異常問題
伺服器主機網卡資訊配置中,盡量選擇 nat 模式或者僅主機模式網卡進行配置,不要選擇LAN 區段網卡配置方式,否則根據虛拟軟體網絡工作原理,LAN 區段網卡配置模式無法進行路由的轉發,會影響最終配置效果。
作者:慘綠少年
出處:http://clsn.io
本文版權歸作者所有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接配接,否則保留追究法律責任的權利。