Q:

How to bind VSFTPD to a specific domain name on a shared hosting?

Good day. I have a Ubuntu 16.04 VPS, on which I configured a shared hosting with two virtual hosts on the same IP (eg. domain1.com and domain2.com). I want to run the FTP server, and I want only domain1.com allowed, but not domain2.com. I was adviced to use VSFTPD to do that, but I couldn't find any howto. Please help. And sorry for bad English :)

A:

All needed iptables commands
clear existing chains
sudo iptables --flush
sudo iptables --delete-chain

allow loopback
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A OUTPUT -o lo -j ACCEPT

allow all ICMP
sudo iptables -A INPUT -p icmp --icmp-type any -j ACCEPT
sudo iptables -A OUTPUT -p icmp -j ACCEPT

allow established connections
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

allow public services
but deny ftp for domain `domain2.com
FTP
sudo iptables -I INPUT -p tcp --dport 21 -m string --string "Host: domain2.com" --algo bm -j DROP
sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT

HTTP
sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

HTTPS
sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

SSH
sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT

allow forward
sudo iptables -P FORWARD ACCEPT

deny all accept above rules 
sudo iptables -A INPUT -j DROP

default policies
sudo iptables -P INPUT DROP
sudo iptables -P OUTPUT ACCEPT

save 
sudo service iptables save

