Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
| docs:guide-user:firewall:fw3_configurations:fw3_nat [2023/09/07 23:18] – consolidate terminology vgaetera | docs:guide-user:firewall:fw3_configurations:fw3_nat [2023/11/01 22:14] – [IPv6 to IPv4 NAT with Tayga] update vgaetera | ||
|---|---|---|---|
| Line 215: | Line 215: | ||
| </ | </ | ||
| - | ==== FTP passthrough | + | ===== Extras |
| - | See also: | + | ==== NAT ==== |
| - | [[packages: | + | Enable masquerading |
| - | + | ||
| - | <code bash> | + | |
| - | opkg update | + | |
| - | opkg install kmod-nf-nathelper | + | |
| - | / | + | |
| - | </ | + | |
| - | + | ||
| - | ==== SIP passthrough ==== | + | |
| - | See also: | + | |
| - | [[packages: | + | |
| - | + | ||
| - | <code bash> | + | |
| - | opkg update | + | |
| - | opkg install kmod-nf-nathelper-extra | + | |
| - | / | + | |
| - | </ | + | |
| - | + | ||
| - | ==== Masquerading | + | |
| - | Enable masquerading on the WAN zone. | + | |
| <code bash> | <code bash> | ||
| uci set firewall.@zone[1].masq=" | uci set firewall.@zone[1].masq=" | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| - | ==== IPv6 masquerading | + | ==== IPv6 NAT ==== |
| - | Enable IPv6 masquerading on the WAN zone. | + | Enable IPv6 masquerading |
| <code bash> | <code bash> | ||
| uci set firewall.@zone[1].masq6=" | uci set firewall.@zone[1].masq6=" | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| Line 258: | Line 239: | ||
| uci set dhcp.lan.ra_default=" | uci set dhcp.lan.ra_default=" | ||
| uci commit dhcp | uci commit dhcp | ||
| - | / | + | service |
| </ | </ | ||
| - | Disable IPv6 source | + | Disable IPv6 source |
| <code bash> | <code bash> | ||
| uci set network.wan6.sourcefilter=" | uci set network.wan6.sourcefilter=" | ||
| uci commit network | uci commit network | ||
| - | / | + | service |
| </ | </ | ||
| - | ==== Selective | + | ==== Selective |
| Enable masquerading selectively for a specific source subnet. | Enable masquerading selectively for a specific source subnet. | ||
| <code bash> | <code bash> | ||
| - | uci -q delete firewall.@zone[1].masq | ||
| uci -q delete firewall.nat | uci -q delete firewall.nat | ||
| uci set firewall.nat=" | uci set firewall.nat=" | ||
| Line 282: | Line 262: | ||
| uci set firewall.nat.target=" | uci set firewall.nat.target=" | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| - | ==== IPv6 selective | + | ==== IPv6 selective |
| Enable IPv6 masquerading selectively for a specific source subnet. | Enable IPv6 masquerading selectively for a specific source subnet. | ||
| <code bash> | <code bash> | ||
| - | uci -q delete firewall.@zone[1].masq6 | ||
| uci -q delete firewall.nat6 | uci -q delete firewall.nat6 | ||
| uci set firewall.nat6=" | uci set firewall.nat6=" | ||
| Line 298: | Line 277: | ||
| uci set firewall.nat6.target=" | uci set firewall.nat6.target=" | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| - | |||
| ==== NPT ==== | ==== NPT ==== | ||
| - | Replace masquerading with IPv4 to IPv4 network prefix translation. | + | Enable |
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| - | NET_DEV=" | + | LAN_PFX=" |
| - | NET_SPFX=" | + | WAN_PFX=" |
| - | NET_DPFX=" | + | . / |
| + | network_flush_cache | ||
| + | network_find_wan WAN_IF | ||
| + | network_get_device WAN_DEV " | ||
| nft add rule inet fw4 srcnat \ | nft add rule inet fw4 srcnat \ | ||
| - | oifname ${NET_DEV} snat ip prefix to ip \ | + | oifname ${WAN_DEV} snat ip prefix to ip \ |
| - | saddr map { ${NET_SPFX} : ${NET_DPFX} } | + | saddr map { ${LAN_PFX} : ${WAN_PFX} } |
| EOF | EOF | ||
| - | uci -q delete firewall.@zone[1].masq | ||
| uci -q delete firewall.npt | uci -q delete firewall.npt | ||
| uci set firewall.npt=" | uci set firewall.npt=" | ||
| uci set firewall.npt.path="/ | uci set firewall.npt.path="/ | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| ==== IPv6 NPT ==== | ==== IPv6 NPT ==== | ||
| - | Replace IPv6 masquerading with IPv6 to IPv6 network prefix translation. | + | Enable |
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| - | NET_DEV=" | + | LAN_PFX=" |
| - | NET_SPFX=" | + | . / |
| - | NET_DPFX="fd00:2::/64" | + | network_flush_cache |
| + | network_find_wan6 WAN_IF | ||
| + | network_get_device WAN_DEV " | ||
| + | network_get_prefix6 WAN_PFX | ||
| nft add rule inet fw4 srcnat \ | nft add rule inet fw4 srcnat \ | ||
| - | oifname ${NET_DEV} snat ip6 prefix to ip6 \ | + | oifname ${WAN_DEV} snat ip6 prefix to ip6 \ |
| - | saddr map { ${NET_SPFX} : ${NET_DPFX} } | + | saddr map { ${LAN_PFX} : ${WAN_PFX} } |
| EOF | EOF | ||
| - | uci -q delete firewall.@zone[1].masq6 | ||
| uci -q delete firewall.npt6 | uci -q delete firewall.npt6 | ||
| uci set firewall.npt6=" | uci set firewall.npt6=" | ||
| uci set firewall.npt6.path="/ | uci set firewall.npt6.path="/ | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| - | ==== IPv6 to IPv4 NAT ==== | + | ==== Symmetric dynamic IPv6 NPT ==== |
| - | Set up NAT64 for IPv6-only networks/clients. | + | Enable symmetric dynamic IPv6 to IPv6 network prefix translation. |
| + | |||
| + | <code bash> | ||
| + | cat << " | ||
| + | LAN_IF=" | ||
| + | sleep 5 | ||
| + | . / | ||
| + | network_flush_cache | ||
| + | network_get_device LAN_DEV " | ||
| + | network_get_prefix_assignment6 LAN_PFX " | ||
| + | network_find_wan6 WAN_IF | ||
| + | network_get_device WAN_DEV " | ||
| + | network_get_prefix6 WAN_PFX " | ||
| + | nft add rule inet fw4 srcnat \ | ||
| + | oifname ${WAN_DEV} snat ip6 prefix to ip6 \ | ||
| + | saddr map { ${LAN_PFX} : ${WAN_PFX} } | ||
| + | nft add rule inet fw4 srcnat \ | ||
| + | oifname ${LAN_DEV} snat ip6 prefix to ip6 \ | ||
| + | saddr map { ${WAN_PFX} : ${LAN_PFX} } | ||
| + | EOF | ||
| + | uci -q delete firewall.npt6 | ||
| + | uci set firewall.npt6=" | ||
| + | uci set firewall.npt6.path="/ | ||
| + | uci commit firewall | ||
| + | service firewall restart | ||
| + | </ | ||
| + | |||
| + | ==== IPv6 to IPv4 NAT with Jool ==== | ||
| + | Enable IPv6 to IPv4 NAT aka NAT64 for IPv6-only networks | ||
| Use DNS64 to resolve domain names. | Use DNS64 to resolve domain names. | ||
| Line 360: | Line 370: | ||
| uci set jool.nat64.enabled=" | uci set jool.nat64.enabled=" | ||
| uci commit jool | uci commit jool | ||
| - | /etc/init.d/jool restart | + | service jool restart |
| + | </code> | ||
| + | |||
| + | ==== IPv6 to IPv4 NAT with Tayga ==== | ||
| + | Enable IPv6 to IPv4 NAT aka NAT64 for IPv6-only networks with Tayga. | ||
| + | Use DNS64 to resolve domain names. | ||
| + | |||
| + | <code bash> | ||
| + | opkg update | ||
| + | opkg install tayga | ||
| + | uci del_list firewall.lan.network=" | ||
| + | uci add_list firewall.lan.network=" | ||
| + | uci commit firewall | ||
| + | service firewall restart | ||
| + | uci -q delete network.nat64 | ||
| + | uci set network.nat64=" | ||
| + | uci set network.nat64.proto=" | ||
| + | uci set network.nat64.prefix=" | ||
| + | uci set network.nat64.ipv6_addr=" | ||
| + | uci set network.nat64.dynamic_pool=" | ||
| + | uci set network.nat64.ipv4_addr=" | ||
| + | uci commit network | ||
| + | service network | ||
| </ | </ | ||
| Line 368: | Line 400: | ||
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| - | NET_DEV="$(uci -q get network.wan.device)" | + | WAN_TTL="65" |
| - | NET_TTL="65" | + | . / |
| + | network_flush_cache | ||
| + | network_find_wan WAN_IF | ||
| + | network_get_device WAN_DEV | ||
| nft add rule inet fw4 mangle_postrouting \ | nft add rule inet fw4 mangle_postrouting \ | ||
| - | oifname ${NET_DEV} ip ttl set ${NET_TTL} | + | oifname ${WAN_DEV} ip ttl set ${WAN_TTL} |
| EOF | EOF | ||
| uci -q delete firewall.ttl | uci -q delete firewall.ttl | ||
| Line 377: | Line 412: | ||
| uci set firewall.ttl.path="/ | uci set firewall.ttl.path="/ | ||
| uci commit firewall | uci commit firewall | ||
| - | / | + | service |
| </ | </ | ||
| Line 385: | Line 420: | ||
| <code bash> | <code bash> | ||
| cat << " | cat << " | ||
| - | NET_DEV="$(uci -q get network.wan6.device)" | + | WAN_HLIM="65" |
| - | NET_HLIM="65" | + | . / |
| + | network_flush_cache | ||
| + | network_find_wan6 WAN_IF | ||
| + | network_get_device WAN_DEV | ||
| nft add rule inet fw4 mangle_postrouting \ | nft add rule inet fw4 mangle_postrouting \ | ||
| - | oifname ${NET_DEV} ip6 hoplimit set ${NET_HLIM} | + | oifname ${WAN_DEV} ip6 hoplimit set ${WAN_HLIM} |
| EOF | EOF | ||
| uci -q delete firewall.hlim | uci -q delete firewall.hlim | ||
| Line 394: | Line 432: | ||
| uci set firewall.hlim.path="/ | uci set firewall.hlim.path="/ | ||
| uci commit firewall | uci commit firewall | ||
| - | /etc/init.d/firewall restart | + | service firewall restart |
| + | </code> | ||
| + | |||
| + | ==== FTP passthrough ==== | ||
| + | Enable NAT passthrough for FTP using [[packages: | ||
| + | |||
| + | <code bash> | ||
| + | opkg update | ||
| + | opkg install kmod-nf-nathelper | ||
| + | service firewall restart | ||
| + | </code> | ||
| + | |||
| + | ==== SIP passthrough ==== | ||
| + | Enable NAT passthrough for SIP, PPTP, GRE, etc. using [[packages: | ||
| + | |||
| + | <code bash> | ||
| + | opkg update | ||
| + | opkg install kmod-nf-nathelper-extra | ||
| + | service firewall restart | ||
| + | </code> | ||
| + | |||
| + | ==== RTSP passthrough ==== | ||
| + | Enable NAT passthrough for RTSP using [[packages: | ||
| + | |||
| + | <code bash> | ||
| + | opkg update | ||
| + | opkg install kmod-ipt-nathelper-rtsp | ||
| + | service | ||
| </ | </ | ||