Hello World !
分类: LINUX
2012-09-03 12:36:20
1.查看端口状态:
dadmin@BPO_CM1> netstat -anp|grep 10.1.1.200.22
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 ::ffff:10.1.1.200:22 ::ffff:10.1.254.132:59935 ESTABLISHED –
C:\>netstat -ano|find "10.1.1.200:22"
TCP 10.1.254.132:59935 10.1.1.200:22 ESTABLISHED 2328
2.查看使用端口的应用程序:
你也可以查看文件/etc/services,从里面可以找出端口所对应的服务。
(注:SNMP(Simple Network Management Protocol,简单网络管理协议)的前身是简单网关监控协议(SGMP):snmpd)
[root@aes523 ~]# lsof -i:22
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
sshd 4835 root 3u IPv4 14178 TCP *:ssh (LISTEN)
sshd 16941 root 3u IPv4 4872803 TCP aes523.domain.com:ssh->192.168.84.112:60548 (ESTABLISHED)
[root@aes523 ~]#
3.使用iptables关闭端口:
打开eth0上进站、出站端口80:
iptables –I input –i eth0 –p tcp --dport 80 –j ACCEPT
iptables –I output –o eth0 –p tcp --sport 80 –j ACCEPT
关闭eth0上进站、出站端口80:
iptables –I input –i eth0 –p tcp --dport 80 –j DROP
iptables –I output –o eth0 –p tcp --sport 80 –j DROP
[root@aes523 sbin]# iptables --list
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:hosts2-ns
DROP tcp -- anywhere anywhere tcp dpt:hosts2-ns
all -- anywhere anywhere
all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:hosts2-ns
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@aes523 sbin]#