第1章 命令配置
虛擬服務器 |
網卡配置信息 |
虛擬網卡名稱 |
虛擬網卡模式 |
服務器01 |
eth1 |
10.0.0.10/24 |
nat模式 |
服務器02 |
eth2 |
10.0.0.11/24 |
nat模式 |
eth3 |
10.0.1.11/24 |
主機模式 |
|
服務器03 |
eth2 |
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 區段網卡配置模式無法進行路由的轉發,會影響最終配置效果。