0

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 :)

  • If you uses iptables simply add this iptables -I INPUT -p tcp --dport 21 -m string --string "Host: domain2.com" --algo bm -j DROP – 2707974 May 16 '17 at 9:56
1

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
  • The answer suits my needs for now, thanks you. In future I plan to switch to proftpd with its virtual hosts. – Alexander Mudrov May 16 '17 at 12:28
  • vsftpd or proftpd uses ftp protocol and if you user default active setup port is the same 21. This iptables setup will work. :) – 2707974 May 16 '17 at 12:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.