User Tools

Site Tools


сервисы_gateway_и_routing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
сервисы_gateway_и_routing [2018/09/18 13:06]
val [Debian/Ubuntu]
сервисы_gateway_и_routing [2022/12/05 06:44]
val [Linux]
Line 4: Line 4:
  
 ===== Gateway ===== ===== Gateway =====
- 
-==== FreeBSD ==== 
-<​code>​ 
-[gate:~] # sysctl net.inet.ip.forwarding 
- 
-[gate:~] # sysctl net.inet.ip.forwarding=1 
- 
-[gate:~] # cat /​etc/​rc.conf 
-</​code><​code>​ 
-... 
-gateway_enable="​YES"​ 
-... 
-</​code><​code>​ 
-[gate:~] # /​etc/​rc.d/​routing restart 
-</​code>​ 
  
 ==== Debian/​Ubuntu ==== ==== Debian/​Ubuntu ====
Line 28: Line 13:
 net.ipv4.ip_forward = 1 net.ipv4.ip_forward = 1
  
-root@gate:​~#​ cat /​etc/​sysctl.conf+root@gate:​~#​ cat /etc/sysctl.d/​20-my-forward.conf
 </​code><​code>​ </​code><​code>​
-... 
 net.ipv4.ip_forward=1 net.ipv4.ip_forward=1
-... 
 </​code><​code>​ </​code><​code>​
-root@gate:​~#​ sysctl -f+root@gate:​~#​ sysctl -p --system ​
 </​code>​ </​code>​
- 
-===== Управление таблицей маршрутизации ===== 
  
 ==== FreeBSD ==== ==== FreeBSD ====
 <​code>​ <​code>​
-[gate:~] # netstat -rn -f inet+[gate:~] # sysctl net.inet.ip.forwarding
  
-[gate:~] # route delete default+[gate:~] # sysctl net.inet.ip.forwarding=1
  
-[gate:~] # route add default 172.16.1.254 +[gate:~] # cat /etc/rc.conf 
- +</​code><​code>​ 
-[gate:~] # route add 192.168.Y/24 172.16.1.Y +... 
- +gateway_enable="​YES"​ 
-[gate:~] # route delete 192.168.Y/24 +... 
-delete net 192.168.Y.0 +</​code><​code>​ 
- +[gate:~] # /​etc/​rc.d/​routing restart
-[gate:~] # route -n flush+
 </​code>​ </​code>​
 +
 +===== Управление таблицей маршрутизации =====
  
 ==== Linux ==== ==== Linux ====
Line 62: Line 44:
 # ip route help # ip route help
  
-# ip r add 192.168.Y.0/​24 via 172.16.1.Y+gate.isp.un# ip r add 192.168.Y.0/​24 via 172.16.1.Y 
 + 
 +gate# ip r add 192.168.110.0/​24 via 192.168.X.201 
 +gate# ip r add 192.168.120.0/​24 via 192.168.X.202 
 +gate# ip r add 192.168.130.0/​24 via 192.168.X.203 
 + 
 +# ip r del 192.168.Y.0/​24 
 + 
 +ip route add|del blackhole|unreachable 192.168.100+X.201
 </​code>​ </​code>​
  
Line 83: Line 73:
 # route del -host 192.168.100+X.201 reject # route del -host 192.168.100+X.201 reject
 </​code>​ </​code>​
- 
-===== Добаление статических маршрутов на этапе загрузки ===== 
  
 ==== FreeBSD ==== ==== FreeBSD ====
 <​code>​ <​code>​
-[gate:~] # cat /​etc/​rc.conf +[gate:~] # netstat -rn -f inet 
-</​code><​code>​ + 
-... +[gate:~] # route delete default 
-defaultrouter="​172.16.1.254" + 
-gateway_enable="​YES"​ +[gate:~] # route add default ​172.16.1.254 
-static_routes="​netY netZ"​ + 
-route_netY="​192.168.Y.0/24 172.16.1.Y" +[gate:~] # route add 192.168.Y/​24 172.16.1.Y 
-route_netZ="​192.168.Z.0/24 172.16.1.Z"​ + 
-... +[gate:~] # route delete ​192.168.Y/24 
-</​code><​code>​ +delete net 192.168.Y.0 
-[gate:~] # /​etc/​rc.d/​routing start+ 
 +[gate:~] # route -n flush
 </​code>​ </​code>​
 +
 +===== Добаление статических маршрутов на этапе загрузки =====
  
 ==== Debian/​Ubuntu ==== ==== Debian/​Ubuntu ====
 +
 +  * [[https://​linuxconfig.org/​how-to-add-static-route-with-netplan-on-ubuntu-20-04-focal-fossa-linux|How to add static route with netplan]]
 +
 <​code>​ <​code>​
 root@gate:​~#​ cat /​etc/​network/​interfaces root@gate:​~#​ cat /​etc/​network/​interfaces
Line 116: Line 110:
 192.168.Y.0/​24 via 172.16.1.Y dev eth1 192.168.Y.0/​24 via 172.16.1.Y dev eth1
 </​code>​ </​code>​
 +==== FreeBSD ====
 +<​code>​
 +[gate:~] # cat /​etc/​rc.conf
 +</​code><​code>​
 +...
 +defaultrouter="​172.16.1.254"​
 +gateway_enable="​YES"​
 +static_routes="​netY netZ"
 +route_netY="​192.168.Y.0/​24 172.16.1.Y"​
 +route_netZ="​192.168.Z.0/​24 172.16.1.Z"​
 +...
 +</​code><​code>​
 +[gate:~] # /​etc/​rc.d/​routing start
 +</​code>​
 +
 ===== Динамические протоколы маршрутизации ===== ===== Динамические протоколы маршрутизации =====
  
Line 123: Line 132:
  
 === Установка === === Установка ===
- 
-=== FreeBSD === 
-<​code>​ 
-[gate:~] # pkg install quagga 
- 
-[gate:~] # cd /​usr/​local/​etc/​quagga/​ 
-</​code>​ 
  
 === Debian/​Ubuntu === === Debian/​Ubuntu ===
Line 152: Line 154:
 enable password zebra enable password zebra
 </​code>​ </​code>​
- 
-=== Запуск === 
  
 === FreeBSD === === FreeBSD ===
 <​code>​ <​code>​
-[gate:~] # cat /​etc/​rc.conf +[gate:~] # pkg install quagga 
-</​code><​code>​ + 
-... +[gate:~] # cd /​usr/​local/​etc/​quagga/
-quagga_enable="​YES"​ +
-quagga_daemons="​zebra ospfd"​ +
-</​code><​code>​ +
-[gate:~] # /​usr/​local/​etc/rc.d/​quagga ​start+
 </​code>​ </​code>​
  
-=== Debian ===+=== Запуск === 
 + 
 +=== Debian/​Ubuntu ​===
 <​code>​ <​code>​
 # service zebra start # service zebra start
Line 173: Line 171:
 </​code>​ </​code>​
  
-=== Ubuntu ​===+=== FreeBSD ​===
 <​code>​ <​code>​
-root@gate:~# cat /etc/quagga/​daemons+[gate:~# cat /etc/rc.conf
 </​code><​code>​ </​code><​code>​
 ... ...
-zebra=yes +quagga_enable="​YES"​ 
-... +quagga_daemons="​zebra ​ospfd"
-ospfd=yes +
-...+
 </​code><​code>​ </​code><​code>​
-root@gate:​~# ​chown -R quagga ​/etc/quagga/ +[gate:~/usr/local/etc/rc.d/quagga start
- +
-root@gate:​~#​ service ​quagga start+
 </​code>​ </​code>​
  
Line 264: Line 258:
  
 <​code>​ <​code>​
-# cat /​etc/​iproute2/​rt_tables +# ip route show table all  #​Записи таблицы main отображаются без имени
-# ip route show table all+
  
-# ip route show table main+# ip route show 
 +# ip route show table main  #​Все пакеты,​ для которых нет правил,​ обрабатываются маршрутами таблицы main 
 + 
 +# cat /​etc/​iproute2/​rt_tables ​ #​Таблицам можно давать имена
  
 # ip route add default via 172.16.1.254 table 101 # ip route add default via 172.16.1.254 table 101
Line 274: Line 270:
 # ip route show table 101 # ip route show table 101
 # ip route show table 102 # ip route show table 102
-# ip route show table all 
  
-# ip rule add from 192.168.X.0/​25 ​table 101 +# ip route show table all | grep 'table 10[12]'​
-# ip rule add from 192.168.X.128/​25 ​table 102 +
-# ip rule add from 192.168.X.0/​24 to 192.168.X.0/​24 table main+
  
 +# ip rule show
 +
 +# ip rule add prio 100 from 192.168.X.0/​24 to 192.168.X.0/​24 table main
 +# ip rule add prio 200 from 192.168.X.0/​25 table 101
 +# ip rule add prio 300 from 192.168.X.128/​25 table 102
  
 # ip rule show # ip rule show
  
-# ip rule del from any table 101 +# ip rule del prio 300 
-# ip rule del from any table 102+# ip rule del prio 200 
 +# ip rule del prio 100 
 + 
 +# ip route del default via 172.16.1.254 ​table 101 
 +# ip route del default via 172.16.2.254 table 102 
 + 
 +# ip route flush table 101 
 +# ip route flush table 102
 </​code>​ </​code>​
  
Line 294: Line 299:
  
 iptables -t nat -A POSTROUTING -o eth1 -s 192.168.X.0/​24 -j SNAT --to-source 172.16.1.X iptables -t nat -A POSTROUTING -o eth1 -s 192.168.X.0/​24 -j SNAT --to-source 172.16.1.X
-iptables -t nat -A POSTROUTING -o eth3 -s 192.168.X.0/​24 -j SNAT --to-source 172.16.2.X+iptables -t nat -A POSTROUTING -o eth2 -s 192.168.X.0/​24 -j SNAT --to-source 172.16.2.X
  
 conntrack -F conntrack -F
 </​code><​code>​ </​code><​code>​
-# iptables-save ​-c > /​etc/​iptables.rules+# iptables-save > /​etc/​iptables.rules
 </​code><​code>​ </​code><​code>​
-# cat /etc/rc.local+# cat /etc/network/​interfaces
 </​code><​code>​ </​code><​code>​
 ... ...
-# Create tables with specific routing +auto eth0 
-ip route add default via 172.16.1.254 table 101 +iface eth0 inet static 
-ip route add default via 172.16.2.254 table 102+ 
 +        pre-up iptables-restore < /​etc/​iptables.rules 
 +         
 +        post-up ​ip rule add prio 100 from 192.168.X.0/24 to 192.168.X.0/​24 table main 
 +        post-up ip rule add prio 200 from 192.168.X.0/​25 ​table 101 
 +        ​post-up ip rule add prio 300 from 192.168.X.128/​25 table 102 
 +         
 +        address 192.168.X.1 
 +        netmask 255.255.255.0 
 + 
 +auto eth1 
 +iface eth1 inet static 
 + 
 +        post-up ​ip route add default via 172.16.1.254 table 101 
 + 
 +        address 172.16.1.X 
 +        netmask 255.255.255.0 
 + 
 +auto eth2 
 +iface eth2 inet static
  
-# Insert rules for choosing traffic for tables +        post-up ​ip route add default via 172.16.2.254 table 102
-ip rule add from 192.168.X.0/25 table 101 +
-ip rule add from 192.168.X.128/​25 ​table 102 +
-ip rule add from 192.168.X.0/​24 to 192.168.X.0/​24 table main+
  
-exit 0+        address 172.16.2.X 
 +        netmask 255.255.255.0
 </​code>​ </​code>​
сервисы_gateway_и_routing.txt · Last modified: 2023/09/15 12:01 by val