I'm debugging my strange network issue still. to recap, I have ~10Mb/s upload speeds to my server from work when it's GBE end to end all the way from my home server to my desktop at work. I can download stuff and run tunnels and such just fine, but saving or copying anything to the sever is sl-o-o-o-w. I previously thought a misconfig of openssh must be at fault, so I tested many different configuration and encryption options. they all came out about the same: ~1GBE down, 0.01 GBE up. I came to the conclusions that it's not an openssh misconfig. In fact, everything works just fine, just slowly in one direction.
viewtopic-t-1159589-highlight-.html
Today I'm going to set up wireguard and see if the suggestion of several commenters that my bizarre abuse of ssh to open multiple reverse tunnels on each machine must be at fault. My work machines are behind a firewall that allows no incoming connections. My home machine is behind my home firewall that has just one pinhole in it on an nonstandard port for ssh and now another one for wireguard. I have some questions scattered through this, and I may make mistakes, please let me know if I've got it wrong so I can fix it.
Wireguard setup
Wireguard is still relatively new, and while its configuration is not super complex, it's tricky and the documentation s*cks [edit: is still somewhat sparse]. Programmers like to document their work in completely tautological sentences. "The EndPoint keyword is used to specify the end point of the encabulator phlogiston. Be careful to specify only values in DERP format." Wait, what? I exaggerate. But that's how it feels like.
Here is the /etc/wireguard/wg0.conf on my server:
Code: Select all
[Interface]
Address = 10.0.2.1/24
#SaveConfig = true
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o enp2s0 -j MASQUERADE;
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o enp2s0 -j MASQUERADE;
ListenPort = 51820
PrivateKey = ********************************************=
[peer]
PublicKey = *********************************************=
AllowedIPs = 10.0.2.0/24
1) The examples in the wireguard and gentoo documentation are st*pid [edit: Not useful for the majority of use cases]. They just put in nonsense numbers that nobody would use in the real world. Way to confuse the hell out of any body coming into this cold.
2) [edited] CIDR IP addresses with a bit width are used in two different ways, but they have to match in a very specific way between both peers. this is super confusing, but below I try to disentangle it.
2.5) You have to be able to edit these config files using ssh usually on both machines. You need to be root on both machines usually.
3) Address [edited thanks to szatox] is the address the the local machine will use in the *remote* address space. It has nothing to do with anything happening on the local machine. The docs don't really tell you this. It's extra confusing that its got a CIDR width on it as if it were a range of addresses starting at your server's address. But that's not how it works. 10.0.2.1/24 is the specific address 10.0.2.1 in a 32-24=8 bit range of addresses starting from 10.0.2.0 to 10.0.2.254. Everybody remembers this, right? It's how most local networks work. The CIDR width and address range must match on both machines, but the remote machines must not use addresses that collide. "Address" is like in your sshd_config file "ListenAddress", (but that doesn't need a bit width or netmask) -- sshd usually only operates in your local net. Gee it would sure be nice if the config files for client server applications at least tried to use similar terminology.
4) ListenPort This is the equivalent of "Port" in sshd_config. Usually this is the outside port that is used on the public net. I guess it is a kind of consistency to label these two exactly backwards from each other. The default port is 51820, but if you don't specify it, it will be random. I don't understand how anybody would ever talk to a sever that's listening on a random port, but I guess if you're only connecting to a server peer and not ever listening, then having a random open wireguard port at least doesn't hurt anything.
5) PrivateKey and PublicKey are pretty self explanatory, you do a keygen and copy the files similarly as for passwordless login for ssh. It would be nice if there were a script like ssh-copy-id that would reach out to your intended server (remote peer) and exchange the public keys automagically.
6) The [Interface] section is your local machine and [peer] section is the remote host. Why can't they call that server and client? because I don't know why, the authors don't find it confusing, so it's all good. It's good that the sections are simple and contained in the same file. They wanted I guess to emphasize that all machines are created equal. How about [local] and [remote]? Because honestly your local machine is also a peer and the remote machine also has an interface. So don't be confused.
7) Lots of stuff gets saved persistently, whether you like it or not. There is a SaveConfig keyword: it is the road to hell. How many times did I stop the service, change wg0.conf and restart it only to have the daemon change it back. Maybe once you have a stable config turn it on. But for example if your server's public IP changes you are pretty hosed. I don't know how you use dynamic dns with wireguard, a problem for another day. There must be a way, but not if the config file is constantly overwritten.
8) EndPoint is where you can specify a public network name and port to connect to. But it looks like once it connects it saves that state forever. Its SaveConfig overwrote my DDNS name for my server with its ip address. After I deleted the endpoint it still kept working through a restart, but I really wish it didn't. Once "SaveConfig" was set to false things started to be come less frustrating.
9) AllowedIPs You don't get to specify the address of your remote peer. I repeat, you don't get to specify the address of your remote peer. Your remote peer tells *you* what its IP address in the private network is, which it specifies in its own [interface] section. You should specify the address *range* your remote host could be in. You might as well put the base of the range, but the way CIDR's work, you can use any address within the range and it has no effect. Unless you get it wrong, and the range your remote peer is using and the range you are using don't overlap. Then they won't talk to each other. So: the range specified by AllowedIPs and the range specified by the Address keyword on the peer server you're connecting to need to match. Mostly you will want to use a single ip address here with a "/32" netmask.
Otherwise if you follow the instructions it works out pretty well.
Wireguard Monitoring
It's really hard to tell what the hell wireguard is doing. It seems to "just work" or "just not work". The most useful command is:
Code: Select all
merckx /home/jesnow # wg
interface: wg0
public key: ******************************************=
private key: (hidden)
listening port: 51820
peer: ***********************************************=
endpoint: 130.39.190.4:51820
allowed ips: 10.0.2.0/24
latest handshake: 1 minute, 20 seconds ago
transfer: 151.92 MiB received, 1.28 GiB sent
You can at least learn your actual ip address you're using from ifconfig. But how do you log into your remote peer to find out its ip if you don't have it?
I have to go eat now, but I will return and get to the point eventually. [edit, I'm back]
Wireguard vs ssh -R
11) After using wireguard only a short time, I'm quickly becoming a fan. Ssh is able to create forward and reverse tunnels and manage multiple connections and do port forwarding, but wg appears to be *made* to do this. I have my questions about how to manage resources in the vpn on wg, but overall it seems very fast and powerful. without showing all the data, it seems to have less network overhead on a fast network than ssh does. But the difference between 500Mb/second and 700Mb/s (I did a lot of tests with iperf), isn't really that noticeable. What *is* noticeable is in a wonky network like my workplace seems to have. they claim to have GBE (in fact the big servers have 40GBE) to the outside world, but while my desktop gets its rated 1GBE on the download, on the upload it's throttled (intentionally or not) to 10Mb/s. Like coax 10BaseT speeds, sometimes worse. Wireguard triples that to 30Mb/s compared to ssh, and that is really noticeable in real world applications.
12) Wg on gentoo is well integrated into the init system. So you can add the init to default via rc-update, and it will come up and be available after a reboot (due eg to a power outage). This is pretty hard to do with ssh tunnels. It is doable, but it's hard.
13) Wg solves the TCP over TCP bandwidth killer that ssh tunnels have. That may be the reason for my much better performance.
Cheers,
Jon.

