Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind external IP - google cloud engine

I've a Google Compute Engine running on Ubuntu 16.04, where i want to start a node.js Websocket Server. Whenever i try to start listening on the external IP, i get the error: "Cannot assign requested address". It works with my internal IP or 127.0.0.1, but then i can not access it from outside.

I've created all the necessary firewall rules.

I can not see my external IP when i run ifconfig. Is this a problem? If so, how could i solve this? I already tried to setup a new instance.

And there is no other process listening on that port.

like image 200
fredalex Avatar asked Oct 18 '22 04:10

fredalex


1 Answers

I guess you're binding explicitly to the external IP? You can try omitting the host parameter, which effectively binds to all interfaces, both internal IP and external IP: NodeJs: server.listen(port[, hostname][, backlog][, callback])

If you run ifconfig on the VM, you will find the external IP is not there. I believe the external IP is a virtual IP in Compute Engine, the underlying networking infrastructure automatically translates it to the internal IP.

$ ifconfig
eth0      Link encap:Ethernet  HWaddr 42:01:0a:80:00:02  
          inet addr:10.128.0.2  Bcast:10.128.0.2  Mask:255.255.255.255
          inet6 addr: fe80::4001:aff:fe80:2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1460  Metric:1
          RX packets:1979 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1363 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:252712 (252.7 KB)  TX bytes:182530 (182.5 KB)
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
like image 64
Dagang Avatar answered Oct 21 '22 03:10

Dagang