[gelöst] debian nftable prerouting Frage

Gemeinsam ins Internet mit Firewall und Proxy.
Antworten
Benutzeravatar
joe2017
Beiträge: 1125
Registriert: 07.08.2017 14:29:51

[gelöst] debian nftable prerouting Frage

Beitrag von joe2017 » 08.11.2021 15:37:35

Hallo zusammen,

ich habe eine kleine Frage zu einem nftable prerouting. Ich habe folgende Einträge:

Code: Alles auswählen

table ip nat {
	chain prerouting {
		type nat hook prerouting priority 0; policy accept;
		ip daddr 172.16.6.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.6.0 comment "dnat"
		ip daddr 172.16.7.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.7.0 comment "dnat"
		ip daddr 172.16.8.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.8.0 comment "dnat"
	}
}
Dies funktioniert soweit auch alles.
Jetzt wollte ich eine bestimmte IP aus diesen Bereichen in ein anderes Netz routen. Jedoch funktioniert das nicht. Ich habe folgendes versucht:

Code: Alles auswählen

table ip nat {
	chain prerouting {
		type nat hook prerouting priority 0; policy accept;
		ip daddr 172.16.6.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.6.0 comment "dnat"
		ip daddr 172.16.7.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.7.0 comment "dnat"
		ip daddr 172.16.8.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.8.0 comment "dnat"
		meta l4proto tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
		ip protocol tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
	}
}
Die Regel alleine habe ich getestet und das funktioniert. Jedoch nicht wenn ich zuvor das ganze Netz preroute.

Code: Alles auswählen

table ip nat {
	chain prerouting {
		type nat hook prerouting priority 0; policy accept;
		meta l4proto tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
		ip protocol tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
	}
}
Weiß jemand wie ich das genau machen muss?
Zuletzt geändert von joe2017 am 09.11.2021 15:37:26, insgesamt 1-mal geändert.

Benutzeravatar
WinMaik
Beiträge: 327
Registriert: 22.03.2008 10:38:00

Re: debian nftable prerouting Frage

Beitrag von WinMaik » 08.11.2021 16:55:58

Einfach mal in's Blaue geraten:
Ziemlich sicher gewinnt die erste Regel, die greift. Daher würde ich die spezifischere Regel vor die Regeln packen, welche die ganzen Netze betreffen. Oder aber sie in eine andere Chain mit höherer Prio packen.

Benutzeravatar
joe2017
Beiträge: 1125
Registriert: 07.08.2017 14:29:51

Re: debian nftable prerouting Frage

Beitrag von joe2017 » 09.11.2021 09:31:58

Du meinst also entweder so:

Code: Alles auswählen

table ip nat {
	chain prerouting {
		type nat hook prerouting priority 0; policy accept;
		meta l4proto tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
		ip protocol tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
		ip daddr 172.16.6.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.6.0 comment "dnat"
		ip daddr 172.16.7.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.7.0 comment "dnat"
		ip daddr 172.16.8.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.8.0 comment "dnat"
	}
}
Oder so:

Code: Alles auswählen

table ip nat {
	chain preroutingFirst {
		type nat hook prerouting priority 0; policy accept;
		meta l4proto tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
		ip protocol tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
	}
	chain prerouting {
		type nat hook prerouting priority 1; policy accept;
		ip daddr 172.16.6.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.6.0 comment "dnat"
		ip daddr 172.16.7.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.7.0 comment "dnat"
		ip daddr 172.16.8.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.8.0 comment "dnat"
	}
}

Benutzeravatar
joe2017
Beiträge: 1125
Registriert: 07.08.2017 14:29:51

Re: debian nftable prerouting Frage

Beitrag von joe2017 » 09.11.2021 15:37:02

Ich konnte soeben meinen Test machen. Folgendes hat funktioniert:

Code: Alles auswählen

table ip nat {
	chain prerouting {
		type nat hook prerouting priority 0; policy accept;
		meta l4proto tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
		ip protocol tcp ip daddr 172.16.6.45 counter packets 0 bytes 0 dnat to 10.20.6.45 comment "dnat"
		ip daddr 172.16.6.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.6.0 comment "dnat"
		ip daddr 172.16.7.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.7.0 comment "dnat"
		ip daddr 172.16.8.0/24 dnat to ip daddr & 0.0.0.255 | 10.10.8.0 comment "dnat"
	}
}

Antworten