Sziasztok!
Adott egy Zentyal 7-es telepítés (development edition). A belső hálózat négy VLAN-ra van szétszedve:
- 1 - MENEDZSMENT - 192.168.50.0/24
- 5 - LEGACY - régi alhálózat - 192.168.5.0/24
- 51 - PUBLIC - vendég hálózat - 192.168.51.0/24
- 52 - INTRA - belső hálózat - 192.168.52.0/24
Kívülről, WAN irányból van néhány DNAT (port forward) létrehozva Zentyal GUI alól. A 80-as és a 443-as (HTTP, HTTPS) portok az 5-ös VLAN egyik gépére mutatnak (192.168.5.110). Ez eddig szuper, kívülről elérhető a szerver. Nade bentről nem. Bent alatt a PUBLIC és az INTRA hálózatokat értem. Az elegáns megoldás, a split DNS nem járható út, olyan gyorsan változik a kiszolgált hosztok köre, hogy nem tudnám menedzselni. Szeretném megoldani hogy a tűzfal (Zentyal) hairpin NAT segítségével elvégezze a megfelelő NAT-olást. Egyedi tűzfal szabályok a /etc/zentyal/scripts/firewall.postconf állományban létre hozhatóak, de akárhogyan próbálkozom, nem sikerül elérni a DNAT-olt szervert. Van aki csinált már ilyet? Ha igen, neki hogyan sikerült? Köszönöm!
- 474 megtekintés
Hozzászólások
Íme a tűzfal szabályok (a külső IP címem behelyettesítettem ezzel: [-W-A-N--I-P-]
iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 980 packets, 160K bytes)
pkts bytes target prot opt in out source destination
1000 161K premodules all -- * * 0.0.0.0/0 0.0.0.0/0
0 0 DNAT tcp -- eth1 * 0.0.0.0/0 [-W-A-N--I-P-] tcp dpts:65000:65535 to:192.168.5.200
0 0 DNAT tcp -- eth1 * 0.0.0.0/0 [-W-A-N--I-P-] tcp dpt:990 to:192.168.5.200
0 0 DNAT tcp -- eth1 * 0.0.0.0/0 [-W-A-N--I-P-] tcp dpt:21 to:192.168.5.200
0 0 DNAT tcp -- eth1 * 0.0.0.0/0 [-W-A-N--I-P-] tcp dpt:26482 to:192.168.52.213:22
0 0 DNAT tcp -- eth1 * 0.0.0.0/0 [-W-A-N--I-P-] tcp dpt:3306 to:192.168.5.200
16 912 DNAT tcp -- eth1 * 0.0.0.0/0 [-W-A-N--I-P-] tcp dpt:443 to:192.168.5.110
4 232 DNAT tcp -- eth1 * 0.0.0.0/0 [-W-A-N--I-P-] tcp dpt:80 to:192.168.5.110
Chain INPUT (policy ACCEPT 340 packets, 24281 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 470 packets, 44059 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 25 packets, 1456 bytes)
pkts bytes target prot opt in out source destination
795 113K postmodules all -- * * 0.0.0.0/0 0.0.0.0/0
767 112K MASQUERADE all -- * eth1 0.0.0.0/0 0.0.0.0/0
Chain postmodules (1 references)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- * vlan51 172.16.52.128/25 0.0.0.0/0
0 0 MASQUERADE all -- * vlan52 172.16.52.128/25 0.0.0.0/0
0 0 MASQUERADE all -- * vlan5 172.16.52.128/25 0.0.0.0/0
0 0 MASQUERADE all -- * vlan1 172.16.52.128/25 0.0.0.0/0
0 0 MASQUERADE all -- * vlan51 172.16.52.0/25 0.0.0.0/0
0 0 MASQUERADE all -- * vlan52 172.16.52.0/25 0.0.0.0/0
3 156 MASQUERADE all -- * vlan5 172.16.52.0/25 0.0.0.0/0
0 0 MASQUERADE all -- * vlan1 172.16.52.0/25 0.0.0.0/0
iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
preinput all -- anywhere anywhere
idrop all -- anywhere anywhere state INVALID
iaccept all -- anywhere anywhere state RELATED,ESTABLISHED
inospoof all -- anywhere anywhere
iexternalmodules all -- anywhere anywhere
iexternal all -- anywhere anywhere
inoexternal all -- anywhere anywhere
imodules all -- anywhere anywhere
iglobal all -- anywhere anywhere
iaccept icmp !f anywhere anywhere icmp echo-request state NEW
iaccept icmp !f anywhere anywhere icmp echo-reply state NEW
iaccept icmp !f anywhere anywhere icmp destination-unreachable state NEW
iaccept icmp !f anywhere anywhere icmp source-quench state NEW
iaccept icmp !f anywhere anywhere icmp time-exceeded state NEW
iaccept icmp !f anywhere anywhere icmp parameter-problem state NEW
idrop all -- anywhere anywhere
Chain FORWARD (policy DROP)
target prot opt source destination
preforward all -- anywhere anywhere
fdrop all -- anywhere anywhere state INVALID
faccept all -- anywhere anywhere state RELATED,ESTABLISHED
fnospoof all -- anywhere anywhere
fredirects all -- anywhere anywhere
fmodules all -- anywhere anywhere
ffwdrules all -- anywhere anywhere
fnoexternal all -- anywhere anywhere
fdns all -- anywhere anywhere
fglobal all -- anywhere anywhere
faccept icmp !f anywhere anywhere icmp echo-request state NEW
faccept icmp !f anywhere anywhere icmp echo-reply state NEW
faccept icmp !f anywhere anywhere icmp destination-unreachable state NEW
faccept icmp !f anywhere anywhere icmp source-quench state NEW
faccept icmp !f anywhere anywhere icmp time-exceeded state NEW
faccept icmp !f anywhere anywhere icmp parameter-problem state NEW
fdrop all -- anywhere anywhere
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
preoutput all -- anywhere anywhere
odrop all -- anywhere anywhere state INVALID
oaccept all -- anywhere anywhere state RELATED,ESTABLISHED
ointernal all -- anywhere anywhere
omodules all -- anywhere anywhere
oglobal all -- anywhere anywhere
oaccept icmp !f anywhere anywhere icmp echo-request state NEW
oaccept icmp !f anywhere anywhere icmp echo-reply state NEW
oaccept icmp !f anywhere anywhere icmp destination-unreachable state NEW
oaccept icmp !f anywhere anywhere icmp source-quench state NEW
oaccept icmp !f anywhere anywhere icmp time-exceeded state NEW
oaccept icmp !f anywhere anywhere icmp parameter-problem state NEW
odrop all -- anywhere anywhere
Chain drop (7 references)
target prot opt source destination
DROP all -- anywhere anywhere
Chain faccept (27 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain fdns (1 references)
target prot opt source destination
Chain fdrop (9 references)
target prot opt source destination
drop all -- anywhere anywhere
Chain ffwdrules (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
Chain fglobal (1 references)
target prot opt source destination
faccept icmp !f 192.168.51.0/24 192.168.52.10 icmp echo-request
faccept icmp !f 192.168.51.0/24 192.168.52.10 icmp echo-reply
faccept icmp !f 192.168.51.0/24 192.168.52.10 icmp destination-unreachable
faccept icmp !f 192.168.51.0/24 192.168.52.10 icmp source-quench
faccept icmp !f 192.168.51.0/24 192.168.52.10 icmp parameter-problem
faccept tcp -- 192.168.51.0/24 192.168.52.10 tcp dpt:netbios-ssn
faccept tcp -- 192.168.51.0/24 192.168.52.10 tcp dpt:printer
faccept tcp -- 192.168.51.0/24 192.168.52.10 tcp dpts:9100:bacula-fd
faccept udp -- 192.168.51.0/24 192.168.52.10 udp dpt:snmp
faccept udp -- 192.168.51.0/24 192.168.52.10 udp dpt:mdns
drop all -- 192.168.51.0/24 192.168.52.0/24
drop all -- 192.168.51.0/24 192.168.5.0/24
drop all -- 192.168.51.0/24 192.168.50.0/24
faccept all -- anywhere anywhere
Chain fmodules (1 references)
target prot opt source destination
Chain fnoexternal (1 references)
target prot opt source destination
fdrop all -- anywhere anywhere state NEW
Chain fnospoof (1 references)
target prot opt source destination
fnospoofmodules all -- anywhere anywhere
fdrop all -- 192.168.52.10 anywhere MAC ! 98:48:27:99:FF:FD
fdrop all -- 192.168.51.0/24 anywhere
fdrop all -- 192.168.52.0/24 anywhere
fdrop all -- 192.168.5.0/24 anywhere
fdrop all -- 192.168.50.0/24 anywhere
Chain fnospoofmodules (1 references)
target prot opt source destination
Chain fredirects (1 references)
target prot opt source destination
faccept tcp -- anywhere 192.168.5.200 state NEW tcp dpts:65000:65535
faccept tcp -- anywhere 192.168.5.200 state NEW tcp dpt:ftps
faccept tcp -- anywhere 192.168.5.200 state NEW tcp dpt:ftp
faccept tcp -- anywhere 192.168.52.213 state NEW tcp dpt:ssh
faccept tcp -- anywhere 192.168.5.200 state NEW tcp dpt:mysql
faccept tcp -- anywhere 192.168.5.110 state NEW tcp dpt:https
faccept tcp -- anywhere 192.168.5.110 state NEW tcp dpt:http
Chain ftoexternalonly (0 references)
target prot opt source destination
faccept all -- anywhere anywhere
fdrop all -- anywhere anywhere
Chain iaccept (20 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain idrop (8 references)
target prot opt source destination
drop all -- anywhere anywhere
Chain iexternal (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
iaccept tcp -- neo.matrixhosting.net anywhere tcp dpt:8443 state NEW
Chain iexternalmodules (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
RETURN all -- anywhere anywhere
iaccept udp -- anywhere anywhere udp dpt:route
iaccept udp -- anywhere anywhere udp dpt:route
iaccept udp -- anywhere anywhere udp dpt:21194
iaccept udp -- anywhere anywhere udp dpt:11194
Chain iglobal (1 references)
target prot opt source destination
iaccept udp -- anywhere anywhere udp dpt:ntp state NEW
iaccept udp -- anywhere anywhere udp spts:bootps:bootpc dpts:bootps:bootpc state NEW
drop udp -- anywhere anywhere udp dpt:tftp state NEW
iaccept udp -- anywhere anywhere udp dpt:domain state NEW
iaccept tcp -- anywhere anywhere tcp dpt:domain state NEW
iaccept tcp -- !192.168.51.0/24 anywhere tcp dpt:ssh state NEW
iaccept tcp -- !192.168.51.0/24 anywhere tcp dpt:8443 state NEW
Chain imodules (1 references)
target prot opt source destination
iaccept udp -- anywhere anywhere udp dpt:route
iaccept udp -- anywhere anywhere udp dpt:route
Chain inoexternal (1 references)
target prot opt source destination
idrop all -- anywhere anywhere state NEW
Chain inointernal (0 references)
target prot opt source destination
Chain inospoof (1 references)
target prot opt source destination
inospoofmodules all -- anywhere anywhere
idrop all -- 192.168.52.10 anywhere MAC ! 98:48:27:99:FF:FD
idrop all -- 192.168.51.0/24 anywhere
idrop all -- 192.168.52.0/24 anywhere
idrop all -- 192.168.5.0/24 anywhere
idrop all -- 192.168.50.0/24 anywhere
Chain inospoofmodules (1 references)
target prot opt source destination
Chain log (0 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Chain oaccept (14 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
Chain odrop (2 references)
target prot opt source destination
drop all -- anywhere anywhere
Chain oglobal (1 references)
target prot opt source destination
oaccept all -- anywhere anywhere state NEW
Chain ointernal (1 references)
target prot opt source destination
oaccept udp -- anywhere anywhere state NEW udp dpt:bootps
Chain omodules (1 references)
target prot opt source destination
oaccept udp -- anywhere anywhere udp dpt:domain
oaccept tcp -- anywhere anywhere tcp dpt:domain
oaccept udp -- anywhere anywhere udp dpt:route
oaccept udp -- anywhere anywhere udp dpt:route
oaccept tcp -- anywhere anywhere tcp dpt:http
Chain preforward (1 references)
target prot opt source destination
Chain preinput (1 references)
target prot opt source destination
Chain preoutput (1 references)
target prot opt source destination
Amivel próbálkoztam, sikertelenül:
iptables -t nat -I POSTROUTING -o vlan5 -s 192.168.52.0/24 -d 192.168.5.110/32 -p tcp -m multiport --dports 80,443 -j MASQUERADE
Köszönöm a segítséget!
- A hozzászóláshoz be kell jelentkezni
A saját hálózataid között inkább routolni próbálj, meg engedni a forgalmat. Az iptables -szel remekül tudod naplózni a csomagokat és látni fogod, hogy hol akad el, legalábbis iptables szinten. Másrészt a célnál visszajövő csomagokat megfelelő default route-tal kell küldened, hogy visszataláljanak.
- A hozzászóláshoz be kell jelentkezni
Minden alhálózat default gateway-e ugyanaz a szerver. Az utolsó IP címek a tartományokban, azaz 192.168.5.254, stb stb. A probléma az, hogy DNS név alapján a külső (WAN) IP címre megy a kérés, és nem talál vissza a csomag, mert arra a portra be van állítva egy DNAT szabály. Ha a belső IP címre mutatna nem lenne gond, az alhálózatok között engedélyezve van a kommunikáció, belső IP címmel elérem a szervert. A külső IP cím miatt van a baj. Elméletben pontosan erre a problémára adna megoldást a hairpin NAT, másnéven NAT loopback. Mindent a talált források alapján próbáltam beállítani, sikertelenül. :(
- A hozzászóláshoz be kell jelentkezni
Nekem van egy tippem, hogy a visszafele jovo csomag nem a public IP-t kapja mint source address, igy a kliens eldobja, mert ugye o a [-W-A-N--I-P-]-tol var valaszcsomagot. szoval jo esellyel kell par SNAT szabaly, hogy ha szervertol jon, akkor annak a [-W-A-N--I-P-] legyen a source cime, ne pedig az adott VLAN-ban levo router lab cime, vagy a server private address.
csomagok (ha jol ertem ez tortenik):
1. klienstol routering: s: kliens internal address -> d: server public address
2: routertol szerverig (DNAT): s: kliens internal address -> d: server internal address
3: szervertol routerig (valasz): s: server internal address -> d: kliens internal address
4: routertol kliensig (masquerade): s: router vlan address -> d: kliens internal address
vagyis a 4. reszben nem ugyanaz lesz a source address, mint az elso reszen a destination.
szerk: sot, lehet visszafele nincs is MASQUERADE, viszont a DNAT miatt kell SNAT.
- A hozzászóláshoz be kell jelentkezni
Igen, így ahogy írod. A DNAT szabályok fixek, GUI alól viszem fel őket. A saját konfig (script) fajlomban próbáltam a MASQUERADE használatával beállítani a hairpin NAT-ot. Jól ertem, hogy ez helyett inkább SNAT kellene?
- A hozzászóláshoz be kell jelentkezni
Valami ilyesmi:
iptables -t nat -I POSTROUTING -o vlan5 -s 192.168.52.0/24 -d 192.168.5.110/32 -p tcp -m multiport --dports 80,443 -j SNAT --to-source [-W-A-N--I-P-]
sot lehet a dportot ki is hagyhatod, vagy sport-ra kell cserelni, mert ugye ez mar a forditott iranyu forgalom.
szerk: a MASQUERADE azert nem lesz jo, mert ebben a szabalyban a router vlan5-be belogo interface cimet fogja megadni mint source address, es a kliens nem oda kuldte eredetileg a csomagot.
- A hozzászóláshoz be kell jelentkezni
Hmm... Egy apró probléma: a WAN IP nem fix. DHCP-n kapom. Megnézem le tudom-e kérdezni a saját szkriptben. Ha nem, akkor csak az a megoldás hogy fix IP cím kell? Ahogy olvastam nem kötelező, pont ez az amit szeretnék megvalósítani. Addig is kipróbálom amit írtál lássuk közelebb érek-e a megoldáshoz. Nagyon szépen köszönöm hogy próbálsz segíteni.
- A hozzászóláshoz be kell jelentkezni
felteteleztem, hogy ha a DNAT szabalyban meg tudod adni a WAN IP-t, akkor azt le tudod vadaszni.
- A hozzászóláshoz be kell jelentkezni
A DNAT szabályokat a szoftver adminisztrációs felülete alól (GUI) vittem fel. Magukat az iptables szabályokat a szoftver generálja, abba beleavatkozási lehetőségem nincs. Csak annyit tudok hozzátenni, hogy létrehozok egy szkriptet amit lefuttat automatikusan, amikor ez a modul (tűzfal) módosul / újratöltődik. Ebbe a szkript fájlba vinném fel azon plusz iptables szabályokat amik a meglévők kiegészítéseként biztosítja nekem a szükséges funkcionalitást.
Ebből az irományból indultam ki:
https://blog.lordvan.com/blog/learned-something-new-today-hairpin-nat-w…
Csak arra nem jövök rá mi a baj ezzel ebben a formában.
- A hozzászóláshoz be kell jelentkezni
Itt az a kerdes, hogy az interface-eid hogy vannak. mert a peldaban nem szurt interface-re egyaltalan, tehat lehet, hogy mivel nalad eth1-re szurt INPUT szabalyokban vannak a DNAT-ok, azokon nem fut at a package, ha belso halozatbol jon (vlan51).
Ugyanis a peldaban azt csinalja, hogy csak a $WEB target fele iranyitott forgalomra tesz MASQUERADE-et, ami annyit jelent, hogy a belso halobol erkezo csomagoknak is at kell haladniuk a a $EXT_IP -> $WEB DNAT szabalyon (ha a DNS tenyleg a $EXT_IP-re oldja fel).
A peldaban elvileg igy mukodik:
1. barhonnan bejon, es destination == $WAN_IP -> preroutingban DNAT szerver belso IP-re (nalad ez eth1 interface-re van korlatozva)
2. ha belso halozatbol jon, es destination == szerver belso IP -> akkor postroutingban MASQUERADE (itt szinten nincs interface szintu korlatozas, ez is okozhat problemat, hogy adott packet nem fog athaladni ezen a szabalyon)
Szoval en elso korben megprobalnam a te eredeti MASQUERADE rule-odat, viszont modositanam a DNAT szabaalyokat, hogy ne legyen benne interface szures (nem tudom, hogy ha pl vlan51 az eth1 fiziaki interface-en van, akkor az netfilterben atmegy-e mindket interface szabalyain).
- A hozzászóláshoz be kell jelentkezni
Viszont ha minden kotel szakad, akkor meg mindig ott van a tcpdump/wireshark mint utolso mentsvar, es megnezheted, hogy egyaltalan eljutnak-e a szerverig a belso halozatbol inditott http keresek. ha odaig sem jutnak el, akkor a lehet probalkozni a zentyalon nezegetni a kulonbozo interface-eken a forgalmat, hogy hol jon be, hol megy ki.
- A hozzászóláshoz be kell jelentkezni
When you masquerade a connection, it means that we set the IP address used on a specific network interface instead of the --to-source option, and the IP address is automatically grabbed from the information about the specific interface.
https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html#MASQ…
- A hozzászóláshoz be kell jelentkezni
Azt hiszem ez a fenti teljesen rossz :)
szoval lassuk:
olyan szabalyok kellenek neked, hogy:
- in interface: vlan51/vlan52, destination: WAN IP eseten DNAT a szereverekre (ugyanazok, mint az in eth1 szabalyok)
- in interface vlan5, out interface vlan51/vlan52 eseten SNAT WAN IP-re
Ez ugye 2+2 szabaly, viszont:
Ezzel az lesz a gond, hogy a masodik 2 szabaly el fogja torni a belso IP alapon valo kommunikaciot. Hogy egyszerre hogy tudod megoldani a kettot, az most nem ugrik be, eleg regen volt ilyennel dolgom.
- A hozzászóláshoz be kell jelentkezni
OK, holnap ott leszek a helyszínen, játszok vele kicsit. Nem merem távolról piszkálni, mert ha elrontok valamit, nem tudom visszacsinálni. :) Az interfészek így néznek ki:
eth1 - egy fizikai interfész, ő a WAN, DHCP-n kap IP címet
eth0 - ez is egy fizikai interfész, ezen vannak a VLAN-ok kialakítva
Az eth0-ra csatlakozik egy menedzselt switch, azon vannak szétkapkodva access portokra. Annyi még a fűszer az egészben (de ez ebbe az egészbe elvileg nem szólhat bele), hogy az egész Hyper-V alatt van virtualizálva.
- A hozzászóláshoz be kell jelentkezni