介紹在網路概念裡,路由是一個很重要的觀念,他負責封包的傳遞及方向,若網域有太多的廣播,這時候就必須要用子網路遮罩,若要連接不同網域,這時候就必須要使用路由器來幫忙了,在這裡我們介紹進階路由 進階路由:
設定靜態路由檔,這個方法的位階順序是最低的 ex : vi /etc/sysconfig/network-scripts/route-eth0, 使用rule(policy)來設定靜態路由,此方法的位階順序比較高,policy總共有255條,設定檔在/etc/iproute2/rt_tables, 預設 0,253,254,255 這四條不能使用, 0 -> unspec , 253 -> default , 254 -> main , 255 -> local ip rule list // show main, default, local 三種 ip route list table main // show main talbe 中所有的路由路徑 ip rule add from 原來網段 to 目的網段 table <num> ip rule add from 192.168.4.0/24 to 192.168.15.0/24 table 100 // 這是暫時的, 必須寫在 script 使開機時啟動執行 ip rule add from 192.168.4.0/24 to 192.168.15.0/24 table test // 在 /etc/iproute2/rt_tables 裡面有加就可以這麼寫 使用 iptables 來紀錄 log iptables -A FORWARD -j LOG -p icmp -s 192.168.4.100 -d 192.168.15.15 --log-level 6 --log-prefix "icmp_pks " iptables -A FORWARD -j LOG -p http -s 來源_IP -d 目的_IP --log-level <0-7> --log-prefix "標記符號" // log-prefix 將紀錄到的封包,給予一個標頭 icmp_pks (並且空一格, 才不會跟後面的訊息連接在一起),syslog.conf內, kern.=info /var/log/iptalbes // 因為 iptables 的 log 是由 kernel 產生,只紀錄階級為 info 的訊息,view /usr/include/sys/syslog.h 紀錄有關 facility.priority 的資料 設定某種封包的路由走法 標記封包: iptables -t mangle -A PREROUTE -j MARK -p tcp --dport 80 -d 192.168.4.100 --set-mark 1 // 主要是這行的設定 (用 iptables -t mangle -L 來顯示 mangle 清單),符合標記(標記為 1)封包的 policy, 使用 table 為 test: ip rule add fwmark 1 table test // 封包標頭有 1 的, 使用 tables 為 test 的規則 設定 table 為 test 的 路由ip route add 192.168.4.0/24 via 192.168.47.250 table test
建立 Tunnel 來架路由 <第一個 Tunnel> modprobe ip_gre // 可用 lsmod | grep ip_gre 檢視是否載入成功 ip tunnel add tun0 mode gre local <local_IP> remote <remote_IP> // 建立一個 tunnel 裝置 tun0 ,ex : ip tunnel add tun0 mode gre local 192.168.115.100 remote 192.168.104.100 ip address add IP/mask dev tun0 // 綁一個 IP 在 tun0 介面上 ,ex : ip a a 192.168.115.1/24 dev tun0 ip link set tun0 up // 將 tun0 介面啟動 ip route add <remote_內部_網段> dev tun0 // 建立雙方 tunnel 內部的路由 ,ex : ip route add 192.168.4.0/24 dev tun0 以上設定完成後,需要等待幾分鐘時間來溝通 <第二個 Tunnel> ip tunnel add tun1 mode gre local <local_IP> remote <remote_IP> // 建立一個 tunnel 裝置 tun1 ,ex : ip tunnel add tun0 mode gre local 192.168.115.100 remote 192.168.102.100 ip address add IP/mask dev tun1 // 綁一個 IP 在 tun1 介面上 ,ex : ip a a 192.168.115.2/24 dev tun1 ip link set tun1 up // 將 tun1 介面啟動 ip route add <remote_內部_網段> dev tun1 // 建立雙方 tunnel 內部的路由 ,ex : ip route add 192.168.2.0/24 dev tun1
VRRP 在兩台 Router(A & B) 上面做以下的設定:
|