配置Linux 内核并利用iptables 做端口映射(1)
配置Linux 内核并利用iptables 做端口映射(1)
配置Linux 内核并利用iptables 做端口映射的具体工作如下:
主机 IP:192.168.1.100
目标机 IP:192.168.2.101
要求将到主机 192.168.1.100:11101 的请求映射到内部网目标机的 sshd 服务端口上,即:192.168.2.101:22。
配置Linux内核(以 2.6.18 为例)
如果执行 iptable -L 出现以下信息,那么就需要重新配置和编译内核:
iptables v1.4.2: can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.
配置选项:
Networking —->
Networking options —->
[*] Network packet filtering (replaces ipchains) —>
Core Netfilter Configuration —>
<*> Netfilter Xtables support (required for ip_tables)
IP: Netfilter Configuration —>
<*> Connection tracking (required for masq/NAT)
<*> IP tables support (required for filtering/masq/NAT)
<*> IP range match support
<*> Packet filtering
<*> REJECT target support
<*> Full NAT
以上配置只为端口映射准备,如果需要其它功能,请根据需要增加相关的配置。
编译安装内核步骤略过。
iptabes
iptables 规则如下:
iptables -t nat -A PREROUTING -p tcp –dport 11101 -d 192.168.1.100 -j DNAT –to-destination 192.168.2.101:22
评论暂时关闭