Hi, don’t know if the title is right, but I will try to explain my situation as best as I can.
I have one main internet service provider, I also have a public /32 address announced through BGP. BGP address is set on “lo” interface, as you can see in the config below.
My BGP upstream is reached through an IPIP tunnel and is working OK.
What is working - traffic from outside is reaching my router and is being processed as it should. Traffic originating from the router(OpenWrt) to external addresses is working as expected( for ex. ping -I MYPUB or wget).
What is not working - NAT. If I do SRCNAT from my internal /24 - it is working, but only traffic originating from OpenWrt itself(192.168.0.1), every other IP in this /24 segment is not being rewritten by the SRCNAT rule.
I want to achieve classic masquerading as it is done on my LAN< - >WAN interfaces.
Below are config snippets with the parts which are related to this topic. If you need something more, feel free to ask.
Edit: Using OpenWrt 24.10.3 r28872-daca7c049b if it makes sense.
/etc/config/network
config interface 'bgpip'
option proto 'static'
option device 'lo'
option delegate '0'
list ipaddr '<MYPUB>/32'
option ip4table 'bgp'
option force_link '0'
option defaultroute '0'
config interface 'bgp_edge'
option proto 'ipip'
option peeraddr '.......'
option mtu '<MYMTU>'
option ttl '64'
option delegate '0'
option defaultroute '0'
option peerdns '0'
config interface 'bgp_internal'
option proto 'static'
option device 'bond0.787'
option ipaddr '192.168.0.1'
option netmask '255.255.255.0'
option delegate '0'
option ip4table 'bgp'
config rule
option src '192.168.0.0/24'
option lookup 'bgp'
config rule
option src '<MYIP>/32'
option lookup 'bgp'
option priority '100'
option in 'bgpip'
config rule
option src '<MYPUB>/32'
option lookup 'bgp'
option priority '100'
config route
option interface 'bgp_edge'
option target '0.0.0.0/0'
option table 'bgp'
/etc/config/firewall - this is not working as expected
config zone
option name 'BGP'
option output 'ACCEPT'
option input 'ACCEPT'
option forward 'ACCEPT'
option masq '1'
option mtu_fix '1'
option family 'ipv4'
list subnet '<MYPUB>/32'
option masq6 '1'
list network 'bgpip'
config zone
option name 'bgp_int'
option input 'ACCEPT'
option output 'ACCEPT'
option forward 'ACCEPT'
option family 'ipv4'
list network 'bgp_internal'
list subnet '192.168.0.0/24'
config forwarding
option src 'bgp_int'
option dest 'BGP'
Finally, this is the rule that makes it work from OpenWrt itself
config nat
option name 'bgp'
option src '*'
option target 'SNAT'
option snat_ip '<MYPUB>'
option src_ip '192.168.0.0/24'
list proto 'all'
option enabled '0'
ip route show table bgp
default dev ipip-bgp_edge proto static scope link
<MYPUB> dev lo proto static scope link
192.168.0.0/24 dev bond0.787 proto static scope link src <MYPUB>
ip rule show table bgp
2: from 192.168.0.0/24 lookup bgp
100: from <MYPUB> lookup bgp
100: from <MYPUB> iif lo lookup bgp
10000: from 192.168.0.1 lookup bgp
10000: from <MYPUB> lookup bgp
20000: from all to 192.168.0.1/24 lookup bgp
20000: from all to <MYPUB> lookup bgp
90001: from all iif lo lookup bgp
90124: from all iif lo lookup bgp