My ISP's DHCP assigns me a private, dynamic IP address (10.151.105.106/26), and in this subnet I have my default gateway. Then I have a static, public IP address assigned, let's say 2.234.35.29/32. I can't connect to the Internet using my private ip address (get an ISP redirection to an error page), but if my outgoing packets have the src address set to 2.234.35.29, the gateway accepts them and everything works. I managed to add 2.234.35.29 as a secondary address to my Ethernet interface, so the situation is more or less:
The point is, FreeBSD chooses 10.151.105.106 as source address for the locally generated outgoing packets, as this is address is in the same subnet of the default gateway, I guess. I want it to set it to generate packets with src=2.234.35.29. This seems to be easily doable in Linux (
I dug deep into this forum, and other people asked similar questions in the past. They were pointed towards policy based routing or to setfib. I read about policy based routing, but it seems to me that it is helpful in setting for example the next hop of a package (
Again: I don't want to do source based routing, but somehow the contrary: route based source selection.
Changing the src address with a NAT rule does the job, but I don't think it's the best thing to do.
I would like the packets to be generated with the correct address in the first place.
What could I try?
Thank you
Code:
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=4209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,VLAN_HWTSO>
ether d0:d4:12:xx:xx:xx
hwaddr 00:00:24:xx:xx:xx
inet6 fe80::xxxx:xxxx:xxxx:xxxx%em0 prefixlen 64 scopeid 0x1
inet 10.151.105.106 netmask 0xffffffc0 broadcast 10.151.105.127 # dhcp assigned
inet 2.234.35.29 netmask 0xffffffff broadcast 2.234.35.29 # manually added
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
media: Ethernet autoselect (100baseTX <full-duplex>)
status: active
The point is, FreeBSD chooses 10.151.105.106 as source address for the locally generated outgoing packets, as this is address is in the same subnet of the default gateway, I guess. I want it to set it to generate packets with src=2.234.35.29. This seems to be easily doable in Linux (
route ... src ...
), but apparently the src
option is not available in FreeBSD's route
command.I dug deep into this forum, and other people asked similar questions in the past. They were pointed towards policy based routing or to setfib. I read about policy based routing, but it seems to me that it is helpful in setting for example the next hop of a package (
ipfw add fwd ...
, that is source based routing), but I couldn't find a way to change the default source address. On the other side, setfib seems conceived to set routing tables per-process, not system wide.Again: I don't want to do source based routing, but somehow the contrary: route based source selection.
Changing the src address with a NAT rule does the job, but I don't think it's the best thing to do.
I would like the packets to be generated with the correct address in the first place.
What could I try?
Thank you