You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Roaming from internal to external server address #210
Mosh doesn't allow the server to roam. But there's one common situation where this would be extremely useful.
I have a server behind a home NAT router. Sometimes my laptop is on my home WiFi, and I can access the server by its internal (RFC 1918) IP address. If I'm outside my home, I instead use the NAT router's public IP, along with a different set of SSH and Mosh ports, which are forwarded to that server. I would like to roam smoothly between these two situations.
Right now I can do it by always using the public IP, even when I'm at home. This introduces extra network latency, but perhaps that's acceptable. It's especially silly when the client and server share a wired Ethernet link but the Internet gateway is connected wirelessly (which is sometimes the case at my house).
In this roaming scenario, the server and client change IP address (as observed from each other) at the same time. So I don't expect a fully automatic solution. Perhaps we can give mosh-client a list of server (IP,port) pairs to try, round-robin, when packets don't seem to be getting through.
An explicit list also mitigates the DoS vulnerability of full server roaming where someone captures a legitimate packet sent by the server and retransmits it from a bogus address to make you roam there. The attacker can only spoof an inactive server address, and perhaps the round-robin behavior limits how much service they can deny.
I'd be interested in playing with this feature, even if we don't have mosh wrapper support for it.
This problem is similar to the IPv6 roaming problem (#81) and the two may have similar solutions.
@kmcallister using the public IP at home doesn't have to introduce latency, I think. If the router is smart enough, it routes directly to the internal IP; if not, you can add such a route yourself, either to the router or to your laptop using DHCP etc.
@andreasvc: Sure, but laptop to router to server is still more latency than laptop to server directly. The router has to receive the packet, rewrite destination address (and maybe port), and send it back out.
Now you could configure an alias on the server's interface which responds to the same IP as the public-facing gateway, and put an explicit route on the client to make that IP link-local (and also screw with ARP?). But that goes far beyond a standard home NAT setup and I think it's asking for trouble.
@kmcallister You should not worry about the latency of your home router, because it's local. It can be laptop-to-server-directly (not that it matters much), using a route added to your computer, e.g. using DHCP.
Your complaint "The router has to receive the packet, rewrite destination address (and maybe port), and send it back out." is true, but trivially so, that's just what routers do. This rewrite is done in say under 1msec, while normally the packet would go through your ISP taking at least 10msec, so there is a huge benefit.
Now that you mention the alias (which you want anyway), maybe that's all you need. You should try adding it and do a trouceroute to confirm. I don't get the asking for trouble bit; it's a one-time configuration and you just have to confirm it's correct. In any case I don't think it's the job of mosh to figure out routing, that seems like asking for more trouble than this one-time manual trick I'm suggesting. Plus the advantage is that it works system+network-wide.
@andreasvc I understand that routing is what routers do... I'm saying that roamable Mosh on my home network uses more routers than it needs to.
I used nping along with a UDP echo server I found to perform some real-world latency measurements, on my home network which looks like this:
The round trip between "client" and "server" over the local wired Ethernet takes an average of 0.66 ms, maximum 0.74 ms (out of 100 samples). If instead I use my public IP and the port forwarding rules on router B, it takes 3.42 ms average, 11.68 ms maximum. So average latency is four times worse and the worst case is fourteen times worse! But you can argue these numbers are still irrelevant at the human scale. That's when I turned on the microwave oven... Now average latency is 7.58 ms, and individual packets are often delayed by 30 ms or more, which is noticeable at human scale. I also get a non-trivial amount of packet loss. Remember, this is for two machines which could be communicating through a local GigE link. It's just silly.
This is hardly the worst network I've ever had to use, either. Sometimes circumstances dictate that your Internet connection is through WiFi to another building and a rat's nest of cheap network hardware. There are entire countries where this sort of thing is the norm. Do you really want your local Mosh connections to die when it's raining outside?
Above all, Mosh aims to make the most of bad network connections. In light of that goal, we shouldn't force people to use a bad connection when a good connection is already available.
The problems seem to be (a) how does mosh-client learn all the IPs it could be using to contact the server [do we have to do ongoing, asynchronous DNS requests or can we get away with making the list of IPs a priori?] and (b) once we have the list of IPs, if more than one of them works, how does mosh-client choose among them?
Typically when we've been talking about "spray sending" (my new term for how we're going to support IPv4/v6 and UDP proxies, or in general the idea of multiple IP targets for the client), we've been talking about having the client start trying multiple IPs if it hasn't heard from the server in a while, and then if it eventually gets a response from one of the targets, settling down to that one.
But for this case here to work properly (where both IPs work, just one is better than the other), don't we need to actually try an IP long enough to get a notion of round-trip link quality, and THEN choose which one to keep? That's a lot more complicated.
Of course we can have dumb heuristics like preferring private-use address space to public address space and preferring IPv4 to IPv6. Maybe that's good enough?
Now that you mention the alias (which you want anyway), maybe that's all you need. You should try adding it and do a trouceroute to confirm. I don't get the asking for trouble bit
Uh, are you really sure this isn't going to cause trouble? We're talking about two different machines with the same public (non-RFC-1918) IP address, running a different set of services. In my diagram the machines are "router B" (Internet interface) and "server" (LAN interface, probably an alias). Of course this fails if you have more than one internal server. It will break internal use of the public IP access for any service on those other servers, not just Mosh. You will need to invalidate ARP entries if you move from the internal LAN to the Ethernet broadcast domain of the router's external interface, which is very common in some environments. You will also need a special route on every client, which needs to go away when the client leaves the internal LAN. And you need to get this right on every operating system on every device which wants to use Mosh. How do you load routes on non-rooted Android? Or you can push that route via DHCP, but now you're serving a screwy network for anyone who connects, even if they don't care about Mosh... It just seems like a total mess. The more I think about this, the more problems I find. So I'm extremely skeptical that this is "something I want anyway", or that it can be tested easily. I've never run a home network like this and I would be very reluctant to do so.
To avoid confusion, we should distinguish this from the much more common (and sane) setup where the same hostname resolves to an internal or an external IP depending on the client's network location. This doesn't work for Mosh roaming because Mosh only resolves the hostname on startup; in fact, mosh-client performs no name queries of any kind.
In any case I don't think it's the job of mosh to figure out routing
I agree! I'm not proposing that Mosh have anything to do with routing. Mosh will remain completely oblivious to the sequence of IP routers which handle a given UDP datagram. I'm just proposing a mechanism for selecting a different endpoint for that datagram. Not even an automatic mechanism. For version 0 of this feature, I would be happy to switch between server IPs by pressing a Mosh escape sequence.
The setup I have is a DSL NAT router, and a server on the LAN. This internal server gets the public IP as an alias, and you can configure a static route on the router saying that its public IP should actually go directly to the server on the lan instead of via the ISP. With this setup you don't need to push routes through DHCP or do any manual configuration except on the router & server. I don't see it as a screwy setup, it's just a single exception for the public IP to have it take the direct route. And it's only on the router, so as soon as you roam to somewhere else you are no longer affected by it. I don't know if your situation is more complicated or if you are just making it too complicated. I do think this issue is on the network (routing) layer and shouldn't be patched up on the application level. In the same vein Firefox could contain a button "clear DNS cache" or "switch to DNS server X", but instead of a feature that's just a clear sign that something is not working or configured as it's supposed to be (seamless).
@kmcallister: I hadn't seen your diagram before. In my scheme you'd set the static route on router A. That kludgenet is amusing; perhaps in that case mesh routing would make sense...
The setup I have is a DSL NAT router, and a server on the LAN. This internal server gets the public IP as an alias, and you can configure a static route on the router saying that its public IP should actually go directly to the server on the lan instead of via the ISP.
The problem is not packets going via the ISP (they wouldn't in any case). The problem is that packets from the client to the server are going to pass through the router first. Adding a special route on the router isn't going to change that.
And how does your scheme deal with multiple servers? They can't both have that alias and route.
I agree that this is a network-layer issue. The network-layer fix is globally routable IPv6 addresses for every host. Unfortunately IPv6 is not widespread and so Mosh (like practically every network program) will need hacks to deal with non-global addresses. Mosh itself lacks IPv6 support at the moment, but that's a separate issue (#81).
It doesn't deal w/multiple servers; prolly better to get multiple public IPs in that case. I disagree that it wouldn't solve the problem; I think it would prevent the packets from being routed through router B, which I assume is causing the latency.
Activity
peterjeremy commentedon Apr 18, 2012
I'd like to see this as well.
andreasvc commentedon Apr 19, 2012
@kmcallister using the public IP at home doesn't have to introduce latency, I think. If the router is smart enough, it routes directly to the internal IP; if not, you can add such a route yourself, either to the router or to your laptop using DHCP etc.
kmcallister commentedon Apr 20, 2012
@andreasvc: Sure, but laptop to router to server is still more latency than laptop to server directly. The router has to receive the packet, rewrite destination address (and maybe port), and send it back out.
Now you could configure an alias on the server's interface which responds to the same IP as the public-facing gateway, and put an explicit route on the client to make that IP link-local (and also screw with ARP?). But that goes far beyond a standard home NAT setup and I think it's asking for trouble.
andreasvc commentedon Apr 20, 2012
@kmcallister You should not worry about the latency of your home router, because it's local. It can be laptop-to-server-directly (not that it matters much), using a route added to your computer, e.g. using DHCP.
Your complaint "The router has to receive the packet, rewrite destination address (and maybe port), and send it back out." is true, but trivially so, that's just what routers do. This rewrite is done in say under 1msec, while normally the packet would go through your ISP taking at least 10msec, so there is a huge benefit.
Now that you mention the alias (which you want anyway), maybe that's all you need. You should try adding it and do a trouceroute to confirm. I don't get the asking for trouble bit; it's a one-time configuration and you just have to confirm it's correct. In any case I don't think it's the job of mosh to figure out routing, that seems like asking for more trouble than this one-time manual trick I'm suggesting. Plus the advantage is that it works system+network-wide.
kmcallister commentedon Apr 27, 2012
@andreasvc I understand that routing is what routers do... I'm saying that roamable Mosh on my home network uses more routers than it needs to.
I used nping along with a UDP echo server I found to perform some real-world latency measurements, on my home network which looks like this:
The round trip between "client" and "server" over the local wired Ethernet takes an average of 0.66 ms, maximum 0.74 ms (out of 100 samples). If instead I use my public IP and the port forwarding rules on router B, it takes 3.42 ms average, 11.68 ms maximum. So average latency is four times worse and the worst case is fourteen times worse! But you can argue these numbers are still irrelevant at the human scale. That's when I turned on the microwave oven... Now average latency is 7.58 ms, and individual packets are often delayed by 30 ms or more, which is noticeable at human scale. I also get a non-trivial amount of packet loss. Remember, this is for two machines which could be communicating through a local GigE link. It's just silly.
This is hardly the worst network I've ever had to use, either. Sometimes circumstances dictate that your Internet connection is through WiFi to another building and a rat's nest of cheap network hardware. There are entire countries where this sort of thing is the norm. Do you really want your local Mosh connections to die when it's raining outside?
Above all, Mosh aims to make the most of bad network connections. In light of that goal, we shouldn't force people to use a bad connection when a good connection is already available.
keithw commentedon Apr 27, 2012
Ok, what should the experience be like here?
The problems seem to be (a) how does mosh-client learn all the IPs it could be using to contact the server [do we have to do ongoing, asynchronous DNS requests or can we get away with making the list of IPs a priori?] and (b) once we have the list of IPs, if more than one of them works, how does mosh-client choose among them?
Typically when we've been talking about "spray sending" (my new term for how we're going to support IPv4/v6 and UDP proxies, or in general the idea of multiple IP targets for the client), we've been talking about having the client start trying multiple IPs if it hasn't heard from the server in a while, and then if it eventually gets a response from one of the targets, settling down to that one.
But for this case here to work properly (where both IPs work, just one is better than the other), don't we need to actually try an IP long enough to get a notion of round-trip link quality, and THEN choose which one to keep? That's a lot more complicated.
Of course we can have dumb heuristics like preferring private-use address space to public address space and preferring IPv4 to IPv6. Maybe that's good enough?
kmcallister commentedon Apr 27, 2012
Uh, are you really sure this isn't going to cause trouble? We're talking about two different machines with the same public (non-RFC-1918) IP address, running a different set of services. In my diagram the machines are "router B" (Internet interface) and "server" (LAN interface, probably an alias). Of course this fails if you have more than one internal server. It will break internal use of the public IP access for any service on those other servers, not just Mosh. You will need to invalidate ARP entries if you move from the internal LAN to the Ethernet broadcast domain of the router's external interface, which is very common in some environments. You will also need a special route on every client, which needs to go away when the client leaves the internal LAN. And you need to get this right on every operating system on every device which wants to use Mosh. How do you load routes on non-rooted Android? Or you can push that route via DHCP, but now you're serving a screwy network for anyone who connects, even if they don't care about Mosh... It just seems like a total mess. The more I think about this, the more problems I find. So I'm extremely skeptical that this is "something I want anyway", or that it can be tested easily. I've never run a home network like this and I would be very reluctant to do so.
To avoid confusion, we should distinguish this from the much more common (and sane) setup where the same hostname resolves to an internal or an external IP depending on the client's network location. This doesn't work for Mosh roaming because Mosh only resolves the hostname on startup; in fact,
mosh-clientperforms no name queries of any kind.I agree! I'm not proposing that Mosh have anything to do with routing. Mosh will remain completely oblivious to the sequence of IP routers which handle a given UDP datagram. I'm just proposing a mechanism for selecting a different endpoint for that datagram. Not even an automatic mechanism. For version 0 of this feature, I would be happy to switch between server IPs by pressing a Mosh escape sequence.
andreasvc commentedon Apr 30, 2012
The setup I have is a DSL NAT router, and a server on the LAN. This internal server gets the public IP as an alias, and you can configure a static route on the router saying that its public IP should actually go directly to the server on the lan instead of via the ISP. With this setup you don't need to push routes through DHCP or do any manual configuration except on the router & server. I don't see it as a screwy setup, it's just a single exception for the public IP to have it take the direct route. And it's only on the router, so as soon as you roam to somewhere else you are no longer affected by it. I don't know if your situation is more complicated or if you are just making it too complicated. I do think this issue is on the network (routing) layer and shouldn't be patched up on the application level. In the same vein Firefox could contain a button "clear DNS cache" or "switch to DNS server X", but instead of a feature that's just a clear sign that something is not working or configured as it's supposed to be (seamless).
andreasvc commentedon Apr 30, 2012
@kmcallister: I hadn't seen your diagram before. In my scheme you'd set the static route on router A. That kludgenet is amusing; perhaps in that case mesh routing would make sense...
kmcallister commentedon Apr 30, 2012
The problem is not packets going via the ISP (they wouldn't in any case). The problem is that packets from the client to the server are going to pass through the router first. Adding a special route on the router isn't going to change that.
And how does your scheme deal with multiple servers? They can't both have that alias and route.
I agree that this is a network-layer issue. The network-layer fix is globally routable IPv6 addresses for every host. Unfortunately IPv6 is not widespread and so Mosh (like practically every network program) will need hacks to deal with non-global addresses. Mosh itself lacks IPv6 support at the moment, but that's a separate issue (#81).
andreasvc commentedon Apr 30, 2012
It doesn't deal w/multiple servers; prolly better to get multiple public IPs in that case. I disagree that it wouldn't solve the problem; I think it would prevent the packets from being routed through router B, which I assume is causing the latency.
kmcallister commentedon Apr 30, 2012
As #212 points out, there are other instances of server changing IP where we won't know all the IPs in advance.
genki commentedon Aug 24, 2013
I have made a simple solution for this issue:
pcchou commentedon Feb 2, 2015
👍