I have some problems making my outgoing IP address configuration permanent. I googled a lot and I do not find configuration that work for me.
Assume my network is 192.168.1.0/24 with default gateway 192.168.1.1. This is my router with NAT and public IP address 188.8.131.52. To this IP address, the hosting provider routes another IP address, 184.108.40.206, which is routed further to my server with private IP address 192.168.1.17 which is statically assigned by DHCP. The default gateway is also published over a DHCP server. And IP address 220.127.116.11 is in my case treated as a server public IP address and server outgoing communication must start from this IP address.
So if I do:
ip route add default via 192.168.1.1 src 18.104.22.168 I can reach the Internet and if I do curl ipinfo.io, my public IP address is 22.214.171.124.
So to make this changes permanent I added:
[robi@centos7-1 ~]$ cat /etc/sysconfig/network-scripts/route-ens160 default via 192.168.1.1 src 126.96.36.199
[robi@centos7-1 ~]$ cat /etc/sysconfig/network-scripts/ifcfg-ens160 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp DEFROUTE=no noIPV4_FAILURE_FATAL=no IPV6INIT=no IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME=ens160 UUID=755cd596-ce8c-4798-8816-4e19b255ae38 DEVICE=ens160 ONBOOT=yes IPADDR=188.8.131.52 PREFIX=32
So now I am not sure if I am doing something wrong or it is not possible to make this configuration permanent it that way.
IP route after reboot:
[robi@centos7-1 ~]$ ip route 184.108.40.206 dev ens160 proto kernel scope link src 220.127.116.11 metric 100 192.168.1.0/24 dev ens160 proto kernel scope link src 192.168.1.17 metric 100
IP route after ip route add default via 192.168.1.1 src 18.104.22.168:
[robi@centos7-1 ~]$ ip route default via 192.168.1.1 dev ens160 src 22.214.171.124 126.96.36.199 dev ens160 proto kernel scope link src 188.8.131.52 metric 100 192.168.1.0/24 dev ens160 proto kernel scope link src 192.168.1.17 metric 100
If I set
DEFROUTE=yes and restart the network I can reach the Internet over 192.168.1.17. The local IP address ipifno.io tells me IP address 184.108.40.206 (IP address with NAT over my router), and I do not want this.
Well, is there a solution to set this using a local IP address from the DHCP server? For bonus, is it possible to route this outgoing IP address over a local gateway returned by the DHCP server in some simple way?
And for extra bonus, is it possible to set this second IP address (220.127.116.11 in my case) over DHCP option 33?