Linux tips & tricks: server, open

Those who need to provide themselves, their beloved, access to their servers from anywhere in the world via SSH / RDP / otherwise - a small RTFM / spur.







We need to do without VPN and other bells and whistles, from any device at hand.







And so that the server does not exercise too much.







All you need is knockd , straight arms and 5 minutes of work.







"Everything is on the Internet", of course (even on Habré ), but when it comes to a specific implementation, it starts ...







We will practice with the example of Fedora / CentOS, but it doesn’t matter.







The spur will suit both beginners and the bison of this business, so there will be comments, but shorter.







1. Server





2. Rake Guide



knockd.conf:



Everything is in the mans too (but this is inaccurate), however knockd is a comrade rather stingy with messages, so you need to be very careful.









For example, this:







 open: 11111,22222,33333 close: 22222,11111,33333
      
      





Open 11111 kick will wait for the next kick on 22222. However, this (22222) kick will start to work close and everything will break. It depends on the delay of the client as well. Such things ©.







iptables



If in / etc / sysconfig / iptables this is this:







 *nat :PREROUTING ACCEPT [0:0]
      
      





it doesn’t bother us, then here it is:







 *filter :INPUT ACCEPT [0:0] ... -A INPUT -j REJECT --reject-with icmp-host-prohibited
      
      





Taki interferes.







Since knockd adds rules to the end of the INPUT chain, we get reject.







And to turn off this reject is to open the car to all winds.







In order not to go into iptables, where to put something before (as people suggest) we’ll make it easier:









The result should be:







 *filter :INPUT DROP [0:0] ... #-A INPUT -j REJECT --reject-with icmp-host-prohibited
      
      





You can, of course, make REJECT instead of DROP, but with DROP, bots will have more fun.







3. Customer



In this place the most interesting (from my point of view), since you need to work not only from any beach, but also from any device.







In principle, a number of clients are listed on the project’s website , but this is from the same series “everything is on the Internet”. Therefore, I will list what works here and now at my fingertips.







When choosing a client, you must ensure that it supports the delay option between packets. Yes, the beach, the strife and 100 megabits never guarantee the arrival of packets in the right order at the right time from this place.







And yes - when setting up the client, delay must be selected independently. A lot of timeout - bots will attack, a little - the client will not be in time. There is a lot of delay - the client will not be in time or there will be a conflict of idiots (see "rake"), not enough - the packets will re-enter the Internet.







With timeout = 5s, the fully working option delay = 100..500ms







Windows



No matter how ridiculous it sounds, but google a distinct knock-client for this platform is quite nontrivial. Such that CLI supports delay, TCP - and without bows.







As an option, you can try this here . Apparently my Google is not a cake.







Linux



Everything is simple here:







 dnf install knock -y knock -d <delay> <dst_ip> 11111 22222 33333
      
      





MacOS



The easiest way is to put the port from homebrew:

brew install knock





and draw for yourself body shirts Commanders of the form:







 #!bin/sh knock -d <delay> <dst_ip> 11111 22222 33333
      
      





iOS



The working option is KnockOnD (free, from the store).







Android



"Knock on Ports". Not advertising, but just working. And the developers are quite responsive.







PS markdown on Habr, of course, God bless him someday ...







UPD1 : thanks to a good person, a working client for Windows was found.

UPD2 : another good person recalled that putting new rules at the end of iptables is not always useful. But - it depends.








All Articles