Linux下做地址NAT有很多种方法。比如haproxy、nginx的4层代理,linux自带的iptables等都能实现。haproxy、nginx就不说了,配置相对简单;iptables配置复杂,概念也比较多DNAT、SNAT、PREROUTING、POSTROUTING等等。其实,Linux下有一个叫rinetd的工具,安装简单,配置也不复杂。
1、下载,解压,安装
# cd ~/zhenyutest/
# wget http://www.boutell.com/rinetd/http/rinetd.tar.gz
# tar -xvf ~/zhenyutest/rinetd.tar.gz
# cd ~/zhenyutest/rinetd/
# sed -i 's/65536/65535/g' rinetd.c
# mkdir /usr/man/
# make && make install
cc -DLINUX -g -c -o rinetd.o rinetd.c
rinetd.c:176:6: 警告:与内建函数‘log’类型冲突 [默认启用]
void log(int i, int coSe, int result);
^
cc -DLINUX -g -c -o match.o match.c
gcc rinetd.o match.o -o rinetd
install -m 700 rinetd /usr/sbin
install -m 644 rinetd.8 /usr/man/man8
#
2、创建配置文件
# vi /etc/rinetd.conf
0.0.0.0 8080 192.168.31.22 8080
allow 1.1.1.* #这个配置是用于限制请求IP来源,如无限制可以删除此行.
logfile /var/log/rinetd.log
配置文件格式很简单:[Source Address] [Source Port] [Destination Address] [Destination Port]
3、启动、关闭程序
启动:
# rinetd -c /etc/rinetd.conf
# ps -ef | grep rinetd
root 27346 27300 0 12:34 pts/1 00:00:00 grep --color=auto rinetd
root 32186 1 0 5月16 ? 00:00:00 rinetd -c /etc/rinetd.conf
停止:
# killall rinetd
1、下载,解压,安装
# cd ~/zhenyutest/
# wget http://www.boutell.com/rinetd/http/rinetd.tar.gz
# tar -xvf ~/zhenyutest/rinetd.tar.gz
# cd ~/zhenyutest/rinetd/
# sed -i 's/65536/65535/g' rinetd.c
# mkdir /usr/man/
# make && make install
cc -DLINUX -g -c -o rinetd.o rinetd.c
rinetd.c:176:6: 警告:与内建函数‘log’类型冲突 [默认启用]
void log(int i, int coSe, int result);
^
cc -DLINUX -g -c -o match.o match.c
gcc rinetd.o match.o -o rinetd
install -m 700 rinetd /usr/sbin
install -m 644 rinetd.8 /usr/man/man8
#
2、创建配置文件
# vi /etc/rinetd.conf
0.0.0.0 8080 192.168.31.22 8080
allow 1.1.1.* #这个配置是用于限制请求IP来源,如无限制可以删除此行.
logfile /var/log/rinetd.log
配置文件格式很简单:[Source Address] [Source Port] [Destination Address] [Destination Port]
3、启动、关闭程序
启动:
# rinetd -c /etc/rinetd.conf
# ps -ef | grep rinetd
root 27346 27300 0 12:34 pts/1 00:00:00 grep --color=auto rinetd
root 32186 1 0 5月16 ? 00:00:00 rinetd -c /etc/rinetd.conf
停止:
# killall rinetd