Question

How to redirect IP address to Domain name?

Posted November 29, 2014 3.5k views

Hello guys,
i have bought cloudflare security, and i have noticed my IP address is still can be accessed from IP address. and i have noticed a little DDoS attack at my server today again.
i want to make it like if someone try to access my IP address then it will redirect directly to my domain name(example.com).
maybe it is can stop direct access to my IP address?
well i am not sure i just think maybe it is also one way to stop the direct access on IP address. and one more quest does cloudflare stop all access to our Server or just port 80 and 443? and DDoS attack can be on any port or just 80?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

CloudFlare has a list of IP addresses which can be allowed with iptables, the rest can be dropped.

iptables -A INPUT -p tcp -m multiport --dports 80,443 --src 199.27.128.0/21 -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 80,443 --src 173.245.48.0/20 -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dports 80,443 --src 103.21.244.0/22 -j ACCEPT
[...]
iptables -A INPUT -p tcp -m multiport --dports 80,443 -j DROP

Add all the IP addresses in that list before the DROP statement. Now no one can directly connect to your Droplet via HTTP/HTTPS. Also check CloudFlare frequently to ensure you do not miss IP address changes.

Submit an Answer