端口转发映射的程序叫rinetd,下载地址,直接manke编译安装即可。
[[email protected] src]# wget http://www.boutell.com/rinetd/http/rinetd.tar.gz [[email protected] src]# ls rinetd.tar.gz [[email protected] src]# tar -zxvf rinetd.tar.gz [[email protected] src]# cd rinetd [[email protected] rinetd]# make cc -DLINUX -g -c -o rinetd.o rinetd.c rinetd.c:176: warning: conflicting types for built-in function ‘log’ cc -DLINUX -g -c -o match.o match.c gcc rinetd.o match.o -o rinetd [[email protected] rinetd]# make install install -m 700 rinetd /usr/sbin install -m 644 rinetd.8 /usr/man/man8 install: cannot create regular file `/usr/man/man8‘: No such file or directory make: *** [install] Error 1 [[email protected] rinetd]#
运行make可能会出现错误,需如下修改,将rinetd.c文件中bindPort >= 65536和connectPort >= 65536修改为65535,不然在make的时候会提示超出系统最大定义端口,按n可以查找下一处
[[email protected] rinetd]# vim rinetd.c 544 if ((bindPort == 0) || (bindPort >= 65535)) { 567 if ((connectPort == 0) || (connectPort >= 65535)) {
手动建目录/usr/man/man8
[[email protected] rinetd]# mkdir -p /usr/man/man8 [[email protected] rinetd]# make install cc -DLINUX -g -c -o rinetd.o rinetd.c rinetd.c:176: warning: conflicting types for built-in function ‘log’ gcc rinetd.o match.o -o rinetd install -m 700 rinetd /usr/sbin install -m 644 rinetd.8 /usr/man/man8 [[email protected] rinetd]#
成功后会提示文件路径
install -m 700 rinetd /usr/sbin
install -m 644 rinetd.8 /usr/man/man8
建立配置文件/etc/rinetd.conf,内容格式:源IP 源端口 要跳转的IP 要跳转的端口
例如将所有发往本机80端口的请求转发到192.168.4.247的80端口
[[email protected] rinetd]# vim /etc/rinetd.conf 0.0.0.0 80 192.168.4.247 80
启动程序并将rinetd加入开机启动
[[email protected] rinetd]# /usr/sbin/rinetd [[email protected] rinetd]# netstat -anltup|grep rinetd tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25019/rinetd [[email protected] rinetd]# cat /etc/rc.d/rc.local |grep -v "#" /usr/sbin/rinetd -c /etc/rinetd.conf touch /var/lock/subsys/local [[email protected] rinetd]# killall -9 rinetd [[email protected] rinetd]# netstat -anltup|grep rinetd [[email protected] rinetd]# /usr/sbin/rinetd [[email protected] rinetd]#
这样的话只要在任意浏览器访问:http://192.168.4.154(rinetd服务器地址)就和访问http://192.168.4.247同样的效果。
注意事项
1. rinetd.conf中绑定的本机端口必须没有被其它程序占用
2. 运行rinetd的系统防火墙应该打开绑定的本机端口
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 2222 -j ACCEPT
3.不支持FTP的跳
时间: 2024-10-29 08:58:26