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 with default gateway This is my router with NAT and public IP address To this IP address, the hosting provider routes another IP address,, which is routed further to my server with private IP address which is statically assigned by DHCP. The default gateway is also published over a DHCP server. And IP address 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 src I can reach the Internet and if I do curl ipinfo.io, my public IP address is

So to make this changes permanent I added:

[robi@centos7-1 ~]$ cat /etc/sysconfig/network-scripts/route-ens160
default via src


[robi@centos7-1 ~]$ cat /etc/sysconfig/network-scripts/ifcfg-ens160

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 dev ens160 proto kernel scope link src metric 100 dev ens160 proto kernel scope link src metric 100

IP route after ip route add default via src

[robi@centos7-1 ~]$ ip route
default via dev ens160 src dev ens160 proto kernel scope link src metric 100 dev ens160 proto kernel scope link src metric 100

If I set DEFROUTE=yes and restart the network I can reach the Internet over The local IP address ipifno.io tells me IP address (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 ( in my case) over DHCP option 33?

  • 1
    There is a lot of important information still missing in this question.
    – RalfFriedl
    Sep 10 '18 at 5:44
  • 8
    @RalfFriedl in that case, please specify what is missing so the OP can include it. Simply pointing out that things are missing without specifying what is missing isn't very useful.
    – terdon
    Sep 10 '18 at 14:28
  • 1
    The local addresses are missing (ip a). The "IP route after reboot" shows no default route. It seems there are multiple external addresses available, but no explanation why.
    – RalfFriedl
    Sep 10 '18 at 16:55
  • 1
    please add you servers IP, your NAT table on your router, is your NAT symetrical ? you shouldn't change the output IP of your server it should be the router. What is your DNS configuration. Could you try to draw a little schematics of your network topology ?
    – Kiwy
    Sep 11 '18 at 12:36
  • If you curl ipinfo.io without doing anything special, what happens? I bet you get the same answer back. Sep 17 '18 at 3:10

Your outgoing IP address for everybody outside is already or without any additional configuration.

The command

ip route add default via src

should already have given you the error message

Error: Invalid prefsrc address.

You don't have to do anything, and you can't force an address different from the public address of your router anyway.

  • Not necessarily. We don't yet know if the router does NAT or if the server really does have external and internal IP addresses.
    – roaima
    Sep 9 '18 at 13:50
  • @roaima We know that the local network has private addresses, and that the server outgoing communication must seem to come from the public IP of the router. We also know that it is not possible to assign a source address that is not an address of one of the local interfaces, and ipinfo.io, which is a public service, shows the correct public address already. So the router has to be a NAT router.
    – RalfFriedl
    Sep 9 '18 at 13:58
  • We do now, yes. At the time I wrote my comment it wasn't definite. (OVH, for one, allows servers to be set up without NAT, having both internal and external IP addresses on the same interface.)
    – roaima
    Sep 10 '18 at 7:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.