How to add external IP to the network scripts in Linux

40 views
Skip to first unread message

Okari Stefanos

unread,
Aug 12, 2017, 5:28:50 PM8/12/17
to gce-discussion
Hello,

I have an service that bind on IP address but only private IP address is listed. How to add my external IP addresses as alias or similar?
OS: Centos 7

I want to bind my service on my external IP and later add two more external IPs and bind other services on those, all on port 80.

Kamran (Google Cloud Support)

unread,
Aug 12, 2017, 7:46:10 PM8/12/17
to gce-discussion

Hello Okari,
 
The external IP address of a VM instance will be NAT'd to its internal IP address before traffic reach to the VM network interface, therefore external IP of a VM can not be used as binding address for a service running inside the VM. However, you can add one or multiple external IP addresses to your VM instance by using forwarding rules. Since target instances do not have a NAT policy applied to them, they can be used for traffic that require non-NAT'ed IP addresses, which can be useful for your use case. 

The steps to create target instance and corresponding forwarding rule objects are described in this article. After creating forwarding rules, you can list forwarding rules and their IP addresses by running the following gcloud commands. They also can be listed in Cloud Console under External IP addresses menu.

$ gcloud compute forwarding-rules list

The route list of the VM also has new entries for the forwarding rules' IP addresses:

$ ip route list table local

Use forwarding rules' external IP addresses for binding different services running inside a VM.


I hope this helps.

Okari Stefanos

unread,
Aug 13, 2017, 4:18:19 PM8/13/17
to gce-discussion
Before I try your suggestion I want to ask you.
Can I bind nginx on 1.1.1.1 port 80 and another nginx on 2.2.2.2 port 80 with your suggestion?

Kamran (Google Cloud Support)

unread,
Aug 16, 2017, 10:41:12 PM8/16/17
to gce-discussion

Hi Okari,

This should be feasible. In order to configure nginx web service to listen on multiple IP addresses and on the same port, please visit this answer on stackoverflow.

Sincerely,
Reply all
Reply to author
Forward
0 new messages