Can You Port Forward the Same Port # to 2 Different Internal IP Addresses?

14

5

If I port forward port 80 UDP on my PC, can I access port 80 from my other laptop?

Octocat

Posted 2015-02-05T12:19:12.127

Reputation: 460

1No; When you forward a port you send all traffic to a single address. If you need 2 devices to receive the data on the same port then you need to forward it to a single device that connects those 2 additional devices to the network ( say another router for instance ). – Ramhound – 2015-02-05T12:21:20.037

1Port 8080 can be used safely as alternative to 80 on the secondary system. So forward 80 to PC and 8080 to notebook if that is whats needed for your requrements. – Overmind – 2015-02-05T12:32:05.450

You write "If I port forward port 80 UDP on my PC, can I access port 80 from my other laptop?" <--- Well obviously otherwise what's the point of port fowarding. – barlop – 2015-08-13T17:44:10.610

AT Ramhound Really huh, ok, , So Why don't you explain how you'd do that? – barlop – 2015-08-13T17:45:01.753

1I recommend you accept VL-80's answer. His answer is very good. It answers what you actually asked-- nobody can speak to how it answers what you meant to ask. – David Betz – 2016-02-12T14:10:19.027

Answers

14

You're asking two different questions here.

Can You Port Forward the Same Port # to 2 Different Internal IP Addresses?

No. Think about it. If a packet arrives to your external address and UDP port 80 (assuming you have only one external IP address), how would your router know which of the two internal IP addresses it should be forwarded to?

If you want to host two different services, you'll need a separate port for each.

If I port forward port 80 UDP on my PC, can I access port 80 from my other laptop?

Yes. Port forwarding generally only affects packets which have port 80 on your side. When someone tries to connect to you, your router will see:

  • incoming packet from other computer's random port X to your port 80
  • outgoing reply from your port 80 to other's port X

But outgoing connections (when you visit a web page elsewhere) will have it reversed from your router's perspective.

  • outgoing packet from your random port X to the other computer's (web server's) port 80
  • incoming reply from the other's port 80 to your port X

So port-forwarding won't affect those at all.

(By the way, HTTP generally runs on TCP. Only Chrome's QUIC experiments use UDP.)

user1686

Posted 2015-02-05T12:19:12.127

Reputation: 283 655

Re "which of the two internal IP addresses it should be forwarded to", why not send to both server 192.168.1.100 and server 192.168.1.101? – Pacerier – 2017-02-13T09:49:02.833

1@Pacerier: What will the client do when it receives two entirely different replies? It won't automagically make two connections where a program requested only one. At best, it'll accept one reply packet and discard the other, which is useless since you can't tell it which server you wanted... unless both .100 and .101 provide exactly the same services (load balancing). At worst, the second reply will even prevent the first connection attempt from finishing (e.g. if the second server keeps receiving packets meant for the first one, it'll keep replying with TCP RSTs) – user1686 – 2017-02-13T11:26:44.263

1@Pacerier: So, in the specific load balancing case (with nearly identical servers), that can be done – see VL-80's answer below for more detail. There are in fact load-balancing programs which duplicate the initial packet and use whichever server was fastest to reply. But if you wanted to host two different websites that way, it wouldn't work because the browser doesn't send the website hostname until long after the TCP connection has been made. – user1686 – 2017-02-13T11:30:43.803

4

Can You Port Forward the Same Port # to 2 Different Internal IP Addresses?

Yes, you can absolutely do it with UDP and to some degree with TCP.

Since UDP is connectionless stateless protocol you can listen for a particular port and once packet arrives you can copy it and send to two different internal destinations. Since there are no handshakes or state tracking all destinations will be able to receive those packets successfully. Samplicator is one of the programs that can do it for you. Note, that this is not a pure Port Forwarding per its definition.

This is possible for TCP, but with some limitations - you can listen for particular port and once packet arrives you can forward it to a particular internal host in a pool. TCP uses connections so once you forwarded an initial packet to a particular internal host it is now necessary to forward rest of the packets in this session to the same internal host.

By using this technology you can have multiple backend servers handling requests to one external destination.

If I port forward port 80 UDP on my PC, can I access port 80 from my other laptop?

This question is little bit unclear. If you forward traffic from your external address to one of the internal hosts then this fact alone does not prevent you to access same port from internal network.

Let's say you forward port 80 from A to B. In the same time C will be able to directly access port 80 on B without any problems.

     A (external IP)
     |
 ---------
 |       |
 B       C

VL-80

Posted 2015-02-05T12:19:12.127

Reputation: 3 867

2The question is about routers. No consumer grade routers have the UDP copy / TCP load balancing features you describe, and none of this is ever called "port forwarding". – Jason C – 2015-06-01T23:25:50.157

4>

  • The question does not specify it must be a consumer level equipment. 2) Regardless of what you wrote the technique I described works.
  • < – VL-80 – 2015-06-02T13:48:07.757

    2No professional level router would have these features either, unless the package includes more than just a router. It's not port forwarding and routers don't perform these functions. The question asked about "port forwarding" and was tagged [tag:router]. Think about the people who would have this same question, find it, and read your answer, and consider whether you're helping or confusing. Your terminology is all wrong anyways. – Jason C – 2015-06-02T14:25:53.273

    You write "This is possible for TCP, .......once you forwarded an initial packet to a particular internal host it is now necessary to forward rest of the packets in this session to the same internal host." <--- So how is this possible with TCP? You mention samplicator for UDP, ok.. so that copies it for UDP.. But what are you suggesting for TCP? – barlop – 2015-08-13T17:41:47.553

    4This answer is good. I was about to say something similar. With UDP, this is what multicast and IGMP is all about. TCP, yes, roundrobin, failover, etc... Yes, routers can do this-- today's routers aren't the blind devices from the 90s. The question is vague enough to allow multiple readings, but this is how I read the qeustion as well. – David Betz – 2016-02-12T14:09:06.850

    1

    You can not forward the same port to multiple IP simultaneously, I have not even seen a router/managed switch that will even let you do that without sending back a config error msg. You can set it up for multiple IPs but only one of the forwarding rules can be enable at a time. So you can disable one enable other and vice versa, but that is a waste You only need to be worried about forwarding ports if you want to access specific ports/service on LAN computer via it's external IP address. Say if you wanted to run 2 webservers on 2 of your LAN PCs and be able to access both of them all of the time, the easiest way to do this is change ports of the services, have one listen on port 80, and the other on 8080 or port you want. 99% of services will allow you to host/listen on any port you want. If you do not specify a port it will fall-back to the service default. There are other more advanced ways of doing things but this is the simplest way, and the advanced methods are not considered or called "Port Forwarding" anyone who says different needs to go back to networking school.

    JohnRB

    Posted 2015-02-05T12:19:12.127

    Reputation: 51

    1

    "I have not even seen a router/managed switch that will even let you do that..." - The consumer-grade Technicolor TC7200.U router will let you add forwarding config for same port(s) to different IP addresses. I am not sure if it actually forwards though.

    – Jonathan Cross – 2016-05-26T09:17:04.420

    -2

    No. Think about it. If a packet arrives to your external address and UDP port 80 (assuming you have only one external IP address), how would your router know which of the two internal IP addresses it should be forwarded to?

    If you want to host two different services, you'll need a separate port for each.

    How does your router know to forward addresses? Because of NAT.

    If you purchase a domain you can set that Domain name as your computers name and NETBIOS name.

    For example 2 different computers hosting websites on different internal but on same external ports must be named after domains or you have to setup your internal DNS server with both domains internal IPs added to it's records to which router connects to and everytime someone tries to connect to domain name (not the public IP address) routers NAT will forward connection accordingly.

    You can't forward exactly identical ports to multiple IPs on same network, but you can use same External ports as long as internal ports are different, vice versa when talking about outgoing network traffic

    user241367

    Posted 2015-02-05T12:19:12.127

    Reputation: 1

    Please don't copy other answers. – Scott – 2019-01-17T16:35:48.563