Iptables controls IP access to the requested URL

Source: Internet
Author: User

The server running environment is Tomcat. The purpose is to allow only specific IP addresses to access a directory,

One way is to use RemoteAddrValve to control access to the VM in the tomcat configuration file server. conf.

You can also use iptables rules. I personally prefer iptables.

For example, to prohibit access to the path http: // 192.168.137.254: 10000/managersns, only access from 192.168.137.101 is allowed.

/Sbin/iptables-a input-I eth0-p tcp -- dport 10000-s 192.168.137.101-m string -- string "/managersns" -- algo bm-j ACCEPT/sbin/iptables- INPUT-I eth0-p tcp -- dport 10000-m string -- string "/managersns" -- algo bm-j DROP

/Sbin/iptables-a input-I eth0-p tcp -- dport 10000-s 192.168.137.101-m string -- string "/managersns" -- algo bm-j ACCEPT

/Sbin/iptables-a input-I eth0-p tcp -- dport 10000-m string -- string "/managersns" -- algo bm-j DROP

The preceding rule is for the eth0 Nic, which can be tracked and modified as needed.

Parameter description:

-M string

Use the string function. string is a module of iptables, that is, string matching.

-String "xxxx"

Define the string content, which can be any character in the URL. If you need to block some types of files or requests, this space is very large and can be imagined.

-Algo bm

Set the character matching query algorithm. Generally, you can use the bm algorithm by default. You can also set the kmp algorithm, which is a more complex algorithm, for more information, see advanced mathematics. (Bm = Boyer-Moore, kmp = Knuth-Pratt-Morris)

-J DROP

This is very effective when video websites are disabled on the company's network. Set it on the gateway Server:

Iptables-a forward-m string -- string "ku6.com" -- algo bm-j DROP iptables-a forward-m string -- string "tudou.com" -- algo bm-j DROP iptables-A FORWARD -m string -- string "ououou.com" -- algo bm-j DROP

Iptables-a forward-m string -- string "ku6.com" -- algo bm-j DROP

Iptables-a forward-m string -- string "tudou.com" -- algo bm-j DROP

Iptables-a forward-m string -- string "ouou.com" -- algo bm-j DROP

The meanings of parameters are as follows:

-A FORWARD

Add the FORWARD chain rule. The preceding rule is for routing enabled (that is, echo 1 & gt;/proc/sys/net/ipv4/ip_forward)

For direct access, you can use INPUT or OUTPUT.

Set the handling method of packets that meet this condition. DROP means discard, which is also the meaning of reject.

Iptables-a input-m string -- string "stringname" -- algo bm-j DROP

Recommended reading:

Iptables-packet filtering (Network Layer) Firewall

Linux Firewall iptables

Iptables + L7 + Squid implements a complete software firewall

Basic use of iptables backup, recovery, and firewall scripts

Detailed description of firewall iptables usage rules in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.