3

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 1.2.3.1. To this IP address, the hosting provider routes another IP address, 1.2.3.4, 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 1.2.3.4 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 1.2.3.4 I can reach the Internet and if I do curl ipinfo.io, my public IP address is 1.2.3.4.

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 1.2.3.4

and

[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=1.2.3.4
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
1.2.3.4 dev ens160 proto kernel scope link src 1.2.3.4 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 1.2.3.4:

[robi@centos7-1 ~]$ ip route
default via 192.168.1.1 dev ens160 src 1.2.3.4
1.2.3.4 dev ens160 proto kernel scope link src 1.2.3.4 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 1.2.3.1 (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 (1.2.3.4 in my case) over DHCP option 33?

closed as unclear what you're asking by RalfFriedl, DarkHeart, Shadur, Kiwy, peterh Sep 12 '18 at 9:09

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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. – Omnifarious Sep 17 '18 at 3:10
1

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

The command

ip route add default via 192.168.1.1 src 1.2.3.4

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.