1-查看网络配置
使用ifconfig命令查看网络接口
查看活动的网络接口信息
[root@test2 jason]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:3B:AF:22 //网络接口的物理地址(MAC地址)
inet addr:192.168.0.103 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe3b:af22/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28872 errors:0 dropped:0 overruns:0 frame:0
TX packets:22384 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1920006 (1.8 MiB) TX bytes:7412928 (7.0 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:820 errors:0 dropped:0 overruns:0 frame:0
TX packets:820 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:61512 (60.0 KiB) TX bytes:61512 (60.0 KiB)
[root@test2 jason]#
- Hwaddr:网络接口的物理地址(Macdizhi ),上面例子中对应的地址为“00:0C:29:3B:AF:22”
- inet addr:网络接口的IP地址,例子中“192.168.0.103”
- Bcast:网络接口所在网络的广播地址 ,例子中“192.168.0.255”
- Mask:网络接口的子网掩码,例子中“255.255.255.0”
查看所有网络接口信息
[root@test2 jason]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:3B:AF:22
inet addr:192.168.0.103 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe3b:af22/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28931 errors:0 dropped:0 overruns:0 frame:0
TX packets:22424 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1923930 (1.8 MiB) TX bytes:7416037 (7.0 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:828 errors:0 dropped:0 overruns:0 frame:0
TX packets:828 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:62120 (60.6 KiB) TX bytes:62120 (60.6 KiB)
pan0 Link encap:Ethernet HWaddr EE:ED:07:BB:3A:33
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@test2 jason]#
查看指定的网络接口信息
[root@test2 jason]# ifconfig pan0
pan0 Link encap:Ethernet HWaddr EE:ED:07:BB:3A:33
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@test2 jason]#
man ifconfig
查看所有网络接口的数据链路层信息
[root@test2 jason]# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:3b:af:22 brd ff:ff:ff:ff:ff:ff
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
link/ether ee:ed:07:bb:3a:33 brd ff:ff:ff:ff:ff:ff
[root@test2 jason]#
查看所有网络接口的网络层信息
[root@test2 jason]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:3b:af:22 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.103/24 brd 192.168.0.255 scope global eth0
inet6 fe80::20c:29ff:fe3b:af22/64 scope link
valid_lft forever preferred_lft forever
3: pan0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
link/ether ee:ed:07:bb:3a:33 brd ff:ff:ff:ff:ff:ff
[root@test2 jason]#
man ip
查看指定网络接口的速率、模式等信息
[root@test2 jason]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
drv probe link
Link detected: yes
[root@test2 jason]#
查看主机名称
[root@test2 jason]# hostname
test2
[root@test2 jason]#
查看路由表条目
[root@test2 jason]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 * 255.255.255.0 U 1 0 0 eth0
[root@test2 jason]#
route -n
[root@test2 jason]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
[root@test2 jason]#
-n
show numerical addresses instead of trying to determine symbolic host names.
This is useful if you are trying to determine why the route to your nameserver
has vanished.
以数字形式显示IP地址,而不是寻找主机名
使用netstat命令查看网络连接情况
- -a:显示当前主机中所有活动的网络连接信息
- -a, --all
Show both listening and non-listening (for TCP this means established connections)
sockets. With the --interfaces option, show interfaces that are not marked
- -n:以数字的形式显示相关信息
- -r:显示路由表信息
--route , -r
Display the kernel routing tables.
- -t:查看TCP协议相关信息
- -u:显示UDP协议相关的信息
- -p:显示与网络连接相关联的进程号、进程名称信息(该选项需要root权限)
-p, --program
Show the PID and name of the program to which each socket belongs.
通常使用“-anpt”组合选项,以数字形式显示当前系统中所有的TCP连接信息,同时显示对应的进程信息
netstat -antp
[root@test2 jason]# netstat -antp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2172/rpcbind
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 2747/perl
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2502/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2347/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2680/master
tcp 0 0 0.0.0.0:33191 0.0.0.0:* LISTEN 2302/rpc.statd
tcp 0 0 192.168.0.103:23 192.168.0.1:3094 ESTABLISHED 22809/in.telnetd
tcp 0 0 192.168.0.103:23 192.168.0.1:3393 ESTABLISHED 23324/in.telnetd
tcp 0 0 :::111 :::* LISTEN 2172/rpcbind
tcp 0 0 :::22 :::* LISTEN 2502/sshd
tcp 0 0 :::23 :::* LISTEN 2510/xinetd
tcp 0 0 ::1:631 :::* LISTEN 2347/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2680/master
tcp 0 0 :::50554 :::* LISTEN 2302/rpc.statd
[root@test2 jason]# ^C
[root@test2 jason]#
establish (v.)
late 14c., from Old French establiss-, present participle stem of establir "cause to
stand still, establish, stipulate, set up, erect, build" (12c., Modern French établir),
from Latin stabilire "make stable," from stabilis "stable" (see stable (adj.)). For the
excrescent e-, see e-. Related: Established; establishing. An established church or
religion is one sanctioned by the state.
netstat -r
[root@test2 jason]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
netstat -rn
[root@test2 jason]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@test2 jason]#
netstat -antup
[root@test2 jason]# netstat -antup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2172/rpcbind
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 2747/perl
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2502/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2347/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2680/master
tcp 0 0 0.0.0.0:33191 0.0.0.0:* LISTEN 2302/rpc.statd
tcp 0 2 192.168.0.103:23 192.168.0.1:3094 ESTABLISHED 22809/in.telnetd
tcp 0 0 192.168.0.103:23 192.168.0.1:3393 ESTABLISHED 23324/in.telnetd
tcp 0 0 :::111 :::* LISTEN 2172/rpcbind
tcp 0 0 :::22 :::* LISTEN 2502/sshd
tcp 0 0 :::23 :::* LISTEN 2510/xinetd
tcp 0 0 ::1:631 :::* LISTEN 2347/cupsd
tcp 0 0 ::1:25 :::* LISTEN 2680/master
tcp 0 0 :::50554 :::* LISTEN 2302/rpc.statd
udp 0 0 0.0.0.0:111 0.0.0.0:* 2172/rpcbind
udp 0 0 0.0.0.0:631 0.0.0.0:* 2347/cupsd
udp 0 0 0.0.0.0:651 0.0.0.0:* 2172/rpcbind
udp 0 0 0.0.0.0:782 0.0.0.0:* 2302/rpc.statd
udp 0 0 0.0.0.0:10000 0.0.0.0:* 2747/perl
udp 0 0 0.0.0.0:52697 0.0.0.0:* 2302/rpc.statd
udp 0 0 :::111 :::* 2172/rpcbind
udp 0 0 :::651 :::* 2172/rpcbind
udp 0 0 :::38890 :::* 2302/rpc.statd
[root@test2 jason]#
过滤端口
[root@test2 jason]# netstat -antup | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2502/sshd
tcp 0 2 192.168.0.103:23 192.168.0.1:3094 ESTABLISHED 22809/in.telnetd
tcp 0 0 :::22 :::* LISTEN 2502/sshd
[root@test2 jason]# ^C
[root@test2 jason]#