title: Open ports only on specific domains
body: <p>I am looking for the right command to open ports only to specific domains. The domain and its subdomain, go to the same server (CentOS)</p>
  
  <p>However, for security reasons, I only want to open the posts on specific subdomains.</p>
  
  <p>On the other domains the ports should not be reachable, so the ftp port 21 should only be open on ftp.domain.com and not on e.g. ssh.domain.com or mysql.domain.com</p>
  
  <p>So I want to block everything (exclude port 80 and 443) and only allow specific ports to specific domains.</p>
  
  <p>example</p>
  
  <ul>
  <li>21 on ftp.domain.com</li>
  <li>22 on ssh.domain.com</li>
  <li>3306 on mysql.domain.com</li>
  </ul>
  
  <p>I know it should work with iptables, but unfortunately I have trouble finding the right command.</p>
  
  <p>I have found this only but i will only accept incoming ports.
  <code>iptables -A OUTPUT -p udp --sport 53 -m string --string "google.com" --algo bm -j ACCEPT</code></p>
  
  <p>Maybe you have a more elegant solution than iptables.</p>