Created
December 22, 2018 22:23
-
-
Save dryliketoast/3a5e12722179e210f0d6a872fca2ea3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://unix.stackexchange.com/questions/125382/migrate-socat-init-script-to-systemd | |
For socat, I use a pure systemd approach. This is an example for a serial loopback: | |
[Unit] | |
Description=Socat Serial Loopback | |
#Before=my-other.service | |
[Service] | |
Type=simple | |
StandardOutput=syslog | |
StandardError=syslog | |
SyslogIdentifier=socat-serial-lo | |
ExecStart=/usr/bin/socat -d -d pty,raw,echo=0,link=/tmp/seriallo-a pty,raw,echo=0,link=/tmp/seriallo-b | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target | |
This can be written to /etc/systemd/system/socat-serial-lo.service (in Ubuntu 16.04+), and then: | |
systemctl daemon-reload | |
systemctl start socat-serial-lo | |
systemctl enable socat-serial-lo # (to start it during bootup) | |
One advantage of this method is that the command line defined by ExecStart can be tested directly from command line without alterations, in order to test the command. | |
answered Sep 21 at 13:45 |
This is really helpful dude!🤗
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The best tool for this that I know of is socat. An example of what you want would look like this:
socat TCP-LISTEN:8010,fork,reuseaddr TCP4::8002
This would listen on port 8010 (on all interfaces) and then forward the traffic to server address on port 8002. Any responses would be forwarded back to the original sender.
Note that the server address should not contain the protocol or path but just the domain or IP address (e.g. www.google.com, NOT http://www.google.com/).
The fork parameter allows multiple connections and the reuseaddr keeps socat from needlessly tying up the address in case it crashes.
https://superuser.com/questions/642666/simple-reverse-proxy