程序的目的是在redhat和AIX上同時(shí)運(yùn)行,對(duì)于很多指令,使用Redhat完成了,但是AIX上沒有,這時(shí),我們選擇Alias的方式,在AIX的Env中,提供具備這樣功能的指令模塊。
下面是研究怎么實(shí)現(xiàn)redhat iptables的stub.
Step (1)about port <=> [inbound ,outbound]
查看端口占用情況:
Issue the command:(as 389 it the port you want to seek )
netstat -Aan | grep 389
this will return:
f1000089c27a2358 tcp4 0 0 *.389 *.* LIST EN
The next step is to take this value that was generated, f1000089c27a2358 and run it against the rmsock command:
rmsock f100089c27a2358 tcpcb
this command will return the process that is holding the socket.
The socket 0xc27a2000 is being held by process 204914 (ndsd).
Step (2)ipsec
什么是ipsec?
ipsec是IEFT提出的network管理標(biāo)準(zhǔn)工具。
ipsec的指令集:
Filters can be defined via the SMIT panel at the fastpath ips4_add_filter
or via the command line, using the genfilt
command. The SMIT method presents a screen similar to the table in the previous section. To create the filter "by hand", the following flags to the genfilt command are used to specify the attributes of the filter rule:
-v
-n
-a
-s
-m
-d
-M
-g
-c
-o
-p
-O
-P
-r
-w
-l
-f
-i
ipsec四個(gè)命令:
To work with TCP/IP filters you only need a few commands, which is explained here and then used in the next section. If you're familiar with AIX commands you see that these follow the same logic of having descriptive prefixes in their names, like mk
, ls
, and rm
, followed by the filt
suffix.
–n
parameter, the new rule is added at the end of the table.
rm
suffix should sound familiar with any UNIX administrator. You use this command whenever you have to remove a filter rule providing its rule ID.
Refer:http://www.darklab.net/resources/aix-ipsec-filtering.html
http://www.ibm.com/developerworks/aix/library/au-aixfiltering/index.html
使用過(guò)程:
(1)啟動(dòng)/關(guān)閉
# smitty ipsec4
(2)是否啟動(dòng)
# lsdev -l ipsec_v4
(3)做個(gè)改變
# chfilt -v 4 -n 3 -i en1 Filter rule 3 for IPv4 has been changed successfully. #
(4)添加新的Rule
## Rules to reject traffic to the Web Application not coming from the Proxy # genfilt -v 4 -a D -s 0 -m 0 -d 172.16.10.45 -M 255.255.255.255 -g N -c tcp -O eq -P 80 -r L -w I -l Y -f Y -i all
(5)設(shè)置log
Now, you are going to configure the syslog daemon to log entries coming from the IP filters in a file that you specify.
## Backup syslog.conf file before modifying it. # cp /etc/syslog.conf /etc/syslog.conf.bak ## Append entry for IP filters logs. # echo "local4.debug /var/adm/ipsec.log" >> /etc/syslog.conf ## Create log file and set permissions (permissions may depend on ## company policies) # touch /var/adm/ipsec.log # chmod 644 /var/adm/ipsec.log ## Refresh the syslog subsystem to activate the new configuration. # refresh -s syslogd 0513-095 The request for subsystem refresh was completed successfully.
(6)配置更新,上面的更新不會(huì)立即生效,除非運(yùn)行下面的命令
# Start the log functionality of the filter rule module # mkfilt -g start # # Activates the filter rules # mkfilt –u
Step (3) iptables
iptables 是linux中防火墻流行的管理工具
針對(duì)本文的作用,僅僅說(shuō)明一種使用,若要詳盡的了解,需耐心的閱讀一個(gè)非常優(yōu)秀的文章,鏈接如下:
Refer:http://man.chinaunix.net/network/iptables-tutorial-cn-1.1.19.html
or http://linux.ccidnet.com/pub/html/tech/iptables/index.htm
我們只是需要使用iptables像外界提供訪問(wèn)本機(jī)資源的端口:
httpPort=80
httpsPort=443
adminPort=8008
那么就使用下面的命令:
cmd 1 :iptables -A INPUT -p tcp --dport ${port} -j ACCEPT
cmd 2 :iptables -A INPUT -p tcp -s localhost -j ACCEPT
cmd 1 .在filter表上添加一條規(guī)則,如果socket pack來(lái)自TCP且push到${port}端口,就接收。
cmd 2 .在filter表上添加一條規(guī)則,如果源IP地址是本機(jī),就接收。
Step (4)mock iptables
如果是用IPsec來(lái)實(shí)現(xiàn)打開端口,允許訪問(wèn)的話,是這樣:
genfilt -v 4 -a P -s 0.0.0.0 -m 0.0.0.0 -d 127.0.0.1 -M 0.0.0.0 -g Y -c tcp –o any –p 0 -O eq -P 80 -r B -w B -l N -f Y -i all
mkfilt -u
所以,就是這樣做一個(gè)mock
#
# cloud_iptables - simulate iptables
#
function aix_iptables
{
echo "aix_iptables:[$@]"
port=""
while [ $# -ne 0 ]; do
case $1 in
--dport)
port=$2
genfilt -v 4 -a P -s 0.0.0.0 -m 0.0.0.0 -d 127.0.0.1 -M 0.0.0.0 -g Y -c tcp –o any –p 0 -O eq -P $port -r B -w B -l N -f Y -i all
shift 1
;;
-s)
sourceip=$2
genfilt -v 4 -a P -s $sourceip -m 0.0.0.0 -d 127.0.0.1 -M 0.0.0.0 -g Y -c tcp –o any –p 0 -O any -P 0 -r B -w B -l N -f Y -i all
shift 1
;;
*)
shift 1
;;
esac
done
}
但是,這還沒有結(jié)束
使用iptables時(shí),我們是這樣:
iptables -A INPUT -p tcp -s localhost -j ACCEPT
service iptables save
語(yǔ)句1 用來(lái)實(shí)現(xiàn)添加一條 rules
語(yǔ)句2 用來(lái)使變更生效
所以,還需要mock service 方法,這樣,在兩個(gè)平臺(tái)中,語(yǔ)句1和語(yǔ)句2就都完成了打開一些防火墻端口的功能。
function aix_service
{
if [ "$1" = "iptables" ]; then
mkfilt -u
else
echo "aix_service $*"
fi
}
對(duì)于系統(tǒng)的判斷:
function on_AIX
{
test "`uname`" = "AIX"
}
如果是AIX系統(tǒng)的話,就要在AIX上執(zhí)行aliases了。
if aliases_on_aix ; then
shopt -s expand_aliases # enable expand aliases,keep it on
alias sudo='aix_sudo'
alias hostname='aix_hostname'
alias iptables='aix_iptables'
alias chkconfig='aix_chkconfig'
alias service='aix_service'
alias
fi
上面是在AIX的bash環(huán)境下進(jìn)行的。
只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。 | ||
![]() |
||
網(wǎng)站導(dǎo)航:
博客園
IT新聞
Chat2DB
C++博客
博問(wèn)
管理
|
||