Implementing multi net NAT

I have downloaded the source code of OpenWRT from Git.

Now I want to implement Multi net NAT in it. For this I want the source code of NAT.

Do anyone know the file path where the NAT is implemented? Any help will be greaful.
Thanks in advance.

NAT is implemented in "nftables", it's part of the Linux kernel. Then, there is the "nft" utility to interact with it. And finally, there is "uci" to govern all the network configuration. Where do you want to start?

On the other hand, then source code that you downloaded does not include the source code for any of that. It is downloaded, from their respective repos, during the building process.

I have implemented NAT on my device and it is working fine.

I want to implement multi net NAT in the device. If you even know the iptables rule for the same you can help me with the same.

I am not 100% sure (still learning nftables) but I think OpenWRT by default NATs all traffic out of its WAN:

root@R7800-2:~# nft list chain 'inet fw4' srcnat_wan
table inet fw4 {
        chain srcnat_wan {
                meta nfproto ipv4 masquerade comment "!fw4: Masquerade IPv4 wan traffic"

So all subnets behind the router are NAtted out via the WAN already by default

Perhaps describe the problem/network setup you have so that you can get a more tailored answer?

Do you want to access the source code to implement something? Or do you just want to know how to configure the existing tools?

Are you aware that OpenWrt uses "nftables" instead of "iptables" now?

What is "multi network NAT", exactly?

1 Like

This is one of those threads again that suspiciously feels like doing someone elses homework / paid work...

@Sahil - please properly define the term "multi net NAT". Yes, you can do masquerading over multiple interfaces, or restricted to particular subnets.