查看網絡接口的命令爲ifconfig,常用的選項爲“-a”,可以列出所有網絡接口的信息。
利用arp -an命令可以查看本機的ARP緩存表,需注意的是ARP緩存表是臨時生成的,在查看前需要ping一下其它主機,生成一條ARP緩存記錄。
查看路由表命令爲route –n。其中有標記“U”爲直連路由,“UG”爲靜態路由。
可以利用netstat –anptu命令,查看本機當前監聽的都有哪些端口。可以利用“|”交由grep命令進行篩選。
ifconfig 命令
Interface Configure
ifconfig 網絡接口
ifconfig -a 列出所有接口 包括禁用的
ethX:以太網連接
lo:本地迴環接口
stiX:ipv6地址網卡接口
fddX:光纖網卡
PPPX:ADSL寬帶或***連接
查看本機路由表
route
-n 顯示數字地址
[root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.100.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
arp
-a:列出所有條目
-n:顯示數字地址
[root@localhost ~]# arp -an
? (192.168.100.1) at 00:50:56:c0:00:01 [ether] on eth0
netstat命令 Network Statistics
-a顯示所有活動連接
-n以數字形式顯示
-p顯示進程信息
-t、-u查看TCP連接、UDP連接
-r顯示路由表
[root@localhost ~]# netstat -anptu|grep ESTABLISHED
tcp 0 0 192.168.100.100:22 192.168.100.1:13593 ESTABLISHED 2504/sshd
tcp 0 52 192.168.100.100:22 192.168.100.1:10317 ESTABLISHED 2207/sshd
查看本機路由表
[root@localhost ~]# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.100.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
查看指定端口是否開啓
[root@localhost ~]# netstat -ln|grep :22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
查看指定服務監聽的端口
[root@localhost ~]# netstat -tulnp|grep sshd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1945/sshd
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 2207/sshd
tcp 0 0 127.0.0.1:6011 0.0.0.0:* LISTEN 2508/sshd
tcp 0 0 :::22 :::* LISTEN 1945/sshd
tcp 0 0 ::1:6010 :::* LISTEN 2207/sshd
tcp 0 0 ::1:6011 :::* LISTEN 2508/sshd
ping命令 測試網絡連接
-c 包個數
-s 包大小
ctrl+c中止測試
追蹤路由過程
traceroute
mtr IP地址
測試DNS解析
host 目標主機
或
nslookup 目標主機
臨時配置
設置路由記錄
網卡配置文件
系統服務 /etc/init.d/network
[root@localhost ~]# ll /etc/sysconfig/network-scripts/ifcfg-eth0
-rw-r--r--. 1 root root 182 8月 9 17:17 /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 設備名
HWADDR=00:0C:29:60:34:B9 MAC地址
TYPE=Ethernet 網絡類型
UUID=f162cfbc-8a6d-4ee7-9450-2f12d6c42249 UUID
ONBOOT=yes 隨network服務啓用
NM_CONTROLLED=yes
BOOTPROTO=none 或者dhcp、static
IPADDR=192.168.100.100 靜態ip地址
NETMASK=255.255.255.0 子網掩碼
DNS1=114.114.114.114 DNS
改完後,重啓網卡服務
6版本可以關閉NetworkManager服務
主機名配置文件
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
主機映射文件
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
dns配置文件
[root@localhost ~]# ll /etc/resolv.conf
-rw-r--r--. 1 root root 228 8月 9 17:18 /etc/resolv.conf
靜態路由配置文件
vim /etc/sysconfig/network-scripts/route-eth0
修改udev規則,重新命名網卡名稱
[root@localhost ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:60:34:b9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
modprobe -rv e1000 卸載網卡驅動
modprobe -v e1000 掛載網卡驅動
scp是非常方便的遠程複製工具:
上傳:scp [-r] 用戶名@服務器:路徑 本地路徑
下載:scp [-r] 本地路徑 用戶名@服務器:路徑
上傳下載時要注意,權限問題。
上傳:本地要有讀取和執行權限,對遠程主機要有讀取、執行、寫入。
下載:本地要有讀取、執行、寫入,對遠程主機要有讀取和執行權限。
[root@localhost ~]# scp /root/anaconda-ks.cfg [email protected]:/mnt/
The authenticity of host '192.168.100.100 (192.168.100.100)' can't be established.
RSA key fingerprint is 1d:4d:3e:cd:0c:7e:78:7d:29:9d:15:4f:a1:fd:b1:c1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.100' (RSA) to the list of known hosts.
[email protected]'s password:
anaconda-ks.cfg 100% 1284 1.3KB/s 00:00
[root@localhost ~]# ll /mnt/anaconda-ks.cfg
-rw-------. 1 root root 1284 8月 11 22:24 /mnt/anaconda-ks.cfg