socat examples


Port forwarding ipv4 to ipv6


To make a ipv6-only service (imaps in this example) accessible for ipv4 clients:

/usr/bin/socat -d -d TCP4-LISTEN:imaps,reuseaddr,fork,su=nobody TCP6:[2001:....:1]:imaps


Put the ipv6 address in the sqare brackets.

systemd and socat


Create a service:
# cat /etc/systemd/system/socat@.service 
[Unit]
Description=ipv4 to ipv6 port forwarding
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/socat -d -d TCP4-LISTEN:%i,reuseaddr,fork,su=nobody TCP6:[2001:....:1]:%i

[Install]
WantedBy=multi-user.target


Install service for imap and imaps:

systemctl daemon-reload
systemctl enable socat@imap.service
systemctl enable socat@imaps.service
systemctl start socat@imap.service
systemctl start socat@imaps.service