ifconfig 命令
显示网络所有接口 ifconfig -a
-bash-3.2$ ifconfig -a
en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
inet 99.99.99.35 netmask 0xffffff00 broadcast 99.99.99.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
en1: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
inet 99.99.99.89 netmask 0xffffff00 broadcast 99.99.99.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
lo0: flags=e08084b<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT>
inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
inet6 ::1/0
tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1
只显示网络接口,不带其它信息。ifconfig -l
-bash-3.2# ifconfig -l
en0 en1 lo0
关闭与启动网络接口 ifconfig en1 up/down
-bash-3.2# ifconfig en1 down
-bash-3.2# ifconfig en1 up
查看已启动的网络接口
-bash-3.2# ifconfig -au
en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
inet 99.99.99.35 netmask 0xffffff00 broadcast 99.99.99.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
lo0: flags=e08084b<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT>
inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
inet6 ::1/0
tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1
-bash-3.2# ifconfig -lu
en0 lo0
查看已关闭的网络接口
-bash-3.2# ifconfig -ad
en1: flags=1e080862,480<BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
inet 99.99.99.89 netmask 0xffffff00 broadcast 99.99.99.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
-bash-3.2# ifconfig -ld
en1
-bash-3.2# netstat -in #带*号的显示为关闭的网络接口,此命令可以查看本机的IP地址
Name Mtu Network Address ZoneID Ipkts Ierrs Opkts Oerrs Coll
en0 1500 link#2 ee.cb.f0.2.30.2 - 477369 0 24513 0 0
en0 1500 99.99.99 99.99.99.35 - 477369 0 24513 0 0
en1* 1500 link#3 ee.cb.f0.2.30.3 - 2539 0 84 0 0
en1* 1500 99.99.99 99.99.99.89 - 2539 0 84 0 0
lo0 16896 link#1 - 93601 0 93608 0 0
lo0 16896 127 127.0.0.1 - 93601 0 93608 0 0
lo0 16896 ::1 0 93601 0 93608 0 0
可以使用ping命令测试网络的连通性
ping -c 5 99.99.99.35
netstat 命令
显示网络接口的格式,是否有多错误的数据包。
-bash-3.2$ netstat -i
Name Mtu Network Address ZoneID Ipkts Ierrs Opkts Oerrs Coll
en0 1500 link#2 ee.cb.f0.2.30.2 - 478409 0 24611 0 0
en0 1500 99.99.99 peng2012 - 478409 0 24611 0 0
en1* 1500 link#3 ee.cb.f0.2.30.3 - 2539 0 84 0 0
en1* 1500 99.99.99 99.99.99.89 - 2539 0 84 0 0
lo0 16896 link#1 - 93767 0 93774 0 0
lo0 16896 127 loopback - 93767 0 93774 0 0
lo0 16896 ::1 0 93767 0 93774 0 0
显示本机的路由表
-bash-3.2$ netstat -rn
Routing tables
Destination Gateway Flags Refs Use If Exp Groups
Route Tree for Protocol Family 2 (Internet):
99.99.99.0 99.99.99.35 UHSb 0 0 en0 - - =>
99.99.99.0 99.99.99.89 UHSb 0 0 en1 - - =>
99.99.99/24 99.99.99.35 U 1 20417 en0 - - =>
99.99.99/24 99.99.99.89 U 0 53 en1 - -
99.99.99.35 127.0.0.1 UGHS 1 509 lo0 - -
99.99.99.89 127.0.0.1 UGHS 0 17 lo0 - -
99.99.99.255 99.99.99.35 UHSb 0 4 en0 - - =>
99.99.99.255 99.99.99.89 UHSb 0 0 en1 - -
127/8 127.0.0.1 U 13 93148 lo0 - -
显示本机所开启服务netstat -a (显示套接字,不显示端口号)
netstat -a
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp 0 0 *.* *.* CLOSED
tcp 0 0 *.* *.* CLOSED
tcp4 0 0 *.* *.* CLOSED
tcp4 0 0 *.daytime *.* LISTEN
tcp 0 0 *.ftp *.* LISTEN
tcp4 0 0 *.ssh *.* LISTEN
tcp 0 0 *.telnet *.* LISTEN
tcp4 0 0 *.smtp *.* LISTEN
tcp4 0 0 *.time *.* LISTEN
tcp4 0 0 *.sunrpc *.* LISTEN
tcp 0 0 *.smux *.* LISTEN
tcp 0 0 *.exec *.* LISTEN
tcp 0 0 *.login *.* LISTEN
tcp 0 0 *.shell *.* LISTEN
tcp 0 0 *.rmc *.* LISTEN
tcp4 0 0 *.writesrv *.* LISTEN
tcp 0 0 *.5335 *.* LISTEN
tcp 0 0 *.5336 *.* LISTEN
tcp 0 0 *.wbem-htt *.* LISTEN
tcp 0 0 *.wbem-htt *.* LISTEN
tcp 0 0 *.6988 *.* LISTEN
......
显示本机所开启服务(显示端口号) netstat -an
netstat -an
Active Internet connections (including servers)
Proto Recv-Q Send-Q Local Address Foreign Address (state)
tcp 0 0 *.* *.* CLOSED
tcp 0 0 *.* *.* CLOSED
tcp4 0 0 *.* *.* CLOSED
tcp4 0 0 *.13 *.* LISTEN
tcp 0 0 *.21 *.* LISTEN
tcp4 0 0 *.22 *.* LISTEN
tcp 0 0 *.23 *.* LISTEN
tcp4 0 0 *.25 *.* LISTEN
tcp4 0 0 *.37 *.* LISTEN
tcp4 0 0 *.111 *.* LISTEN
tcp 0 0 *.199 *.* LISTEN
tcp 0 0 *.512 *.* LISTEN
tcp 0 0 *.513 *.* LISTEN
tcp 0 0 *.514 *.* LISTEN
tcp 0 0 *.657 *.* LISTEN
tcp4 0 0 *.1334 *.* LISTEN
tcp 0 0 *.5335 *.* LISTEN
tcp 0 0 *.5336 *.* LISTEN
tcp 0 0 *.5988 *.* LISTEN
tcp 0 0 *.5989 *.* LISTEN
tcp 0 0 *.6988 *.* LISTEN
.....
显示本机的端口号21是否开启
netstat -an|grep 21.
设置主机IP地址 smit mktcpip (smit tcpip再进一步选择)
Minimum Configuration & Startup
To Delete existing configuration data, please use Further Configuration menus
Type or select values in entry fields.
Press Enter AFTER making all desired changes.
[TOP] [Entry Fields]
* HOSTNAME [peng2012]
* Internet ADDRESS (dotted decimal) [99.99.99.35]
Network MASK (dotted decimal) [255.255.255.0]
* Network INTERFACE en0
NAMESERVER
Internet ADDRESS (dotted decimal) []
DOMAIN Name []
Default Gateway
Address (dotted decimal or symbolic name) []
Cost [] #
Do Active Dead Gateway Detection? no +
[MORE...2]
F1=Help F2=Refresh F3=Cancel F4=List
F5=Reset F6=Command F7=Edit F8=Image
F9=Shell F10=Exit Enter=Do