七层OSI 和四层TCP/IP参考模型:
应用层:最高层,提供用网络与用户应该软件之间的接口服务,如HTTP,FTP,SMTP,POP3
表示层:负责数据格式变换,加密,压缩,恢复等
会话层:用于组织两个会话进程之间的通信
传输层:提供端到端服务;TCP/UDP
网络层:通过路由选择算法为分组通过子网选择最佳路径
数据链路层:
物理层:最底层,利用物理传输介质,为数据链路层提供物理连接
应用层:
传输层:
互联层:
主机-网络层
IP地址:IPv4 主流
IPv6 趋势
A类: 1.0.0.0 - 126.255.255.255
B类: 128.0.0.0 - 191.255.255.255
C类: 192.0.0.0 - 223.255.255.255
特殊地址 10.0.0.0 -10.255.255.255
127.0.0.1
172.16.0.0 -172.31.255.255
192.168.0.0- 192.168.255.255
[root@Freedom1991 /]# ipcalc -bmn 192.168.1.3/24 计算子网掩码,广播,和网络号
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
[root@Freedom1991 /]# route -n 查看路由信息
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
增加一条路由,目的网段;211.220.1.0/24 所有数据通过网关 192.168.1.1 送出,且经过eth0网卡
[root@Freedom1991 /]# route add -net 211.220.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0
[root@Freedom1991 /]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
211.220.1.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0
172.16.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[root@Freedom1991 /]# route del -net 211.220.1.0/24 gw 192.168.1.1 dev eth0
删除
[root@Freedom1991 /]# ifconfig - 查看网络设备接口信息
eth0 Link encap:Ethernet HWaddr 00:0C:29:A0:9B:D5
inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fea0:9bd5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:27697 errors:0 dropped:0 overruns:0 frame:0
TX packets:8761 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2020334 (1.9 MiB) TX bytes:2538083 (2.4 MiB)
Interrupt:19 Base address:0x2000
eth1 Link encap:Ethernet HWaddr 00:0C:29:A0:9B:DF
inet addr:172.16.100.1 Bcast:172.16.255.255 Mask:255.255.0.0
inet6 addr: fe80::20c:29ff:fea0:9bdf/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:81 errors:0 dropped:0 overruns:0 frame:0
TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:15030 (14.6 KiB) TX bytes:1324 (1.2 KiB)
Interrupt:16 Base address:0x2080
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:65536 Metric:1
RX packets:1568 errors:0 dropped:0 overruns:0 frame:0
TX packets:1568 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:89656 (87.5 KiB) TX bytes:89656 (87.5 KiB)
设置一块网卡的子接口,并激活
[root@Freedom1991 /]# ifconfig eth0:0 192.168.1.4 netmask 255.255.255.0 up
[root@Freedom1991 /]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:0C:29:A0:9B:D5
inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fea0:9bd5/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:27971 errors:0 dropped:0 overruns:0 frame:0
TX packets:8892 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2043236 (1.9 MiB) TX bytes:2550985 (2.4 MiB)
Interrupt:19 Base address:0x2000
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:A0:9B:D5
inet addr:192.168.1.4 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2000
可以用setup命令设置网络配置:
查看配置文件:
[root@Freedom1991 /]# cd /etc/sysconfig/network-scripts
[root@Freedom1991 network-scripts]# ls
ifcfg-eth0 ifdown ifdown-ib ifdown-isdn ifdown-routes ifup ifup-eth ifup-ipv6 ifup-plusb ifup-routes ifup-wireless network-functions
ifcfg-eth1 ifdown-bnep ifdown-ippp ifdown-post ifdown-sit ifup-aliases ifup-ib ifup-isdn ifup-post ifup-sit init.ipv6-global network-functions-ipv6
ifcfg-lo ifdown-eth ifdown-ipv6 ifdown-ppp ifdown-tunnel ifup-bnep ifup-ippp ifup-plip ifup-ppp ifup-tunnel net.hotplug
[root@Freedom1991 network-scripts]# cat ifcfg-eth0 网卡1
DEVICE=eth0
TYPE=Ethernet
UUID=d1680cf6-689c-4126-9c78-635e28957da6
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0c:29:a0:9b:d5
DEFROUTE=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
NAME="System eth0"
IPADDR=192.168.1.3
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
USERCTL=no
[root@Freedom1991 network-scripts]# cat ifcfg-eth1 网卡2
CE=eth1
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0c:29:a0:9b:df
DEFROUTE=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
NAME="System eth1"
IPADDR=172.16.100.1
NETMASK=255.255.0.0
DEVICE=eth1
USERCTL=no
[root@Freedom1991 network-scripts]#
netstat:用法详解
-a :显示所有协议和socket连接信息
-n :对应的源IP和目的IP地址
-l: 显示正在监听的信息
-t :TCP协议
-u :UDP协议
-p :服务器名称
[root@Freedom1991 network-scripts]# netstat -antulp
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:21 0.0.0.0:* LISTEN 1878/vsftpd
tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 1833/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1855/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1632/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2276/master
tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3687/sshd
tcp 0 0 0.0.0.0:50831 0.0.0.0:* LISTEN 1593/rpc.statd
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1469/rpcbind
tcp 0 52 192.168.1.3:22 192.168.1.2:4682 ESTABLISHED 3687/sshd
tcp 0 0 :::53 :::* LISTEN 1833/dnsmasq
tcp 0 0 :::22 :::* LISTEN 1855/sshd
tcp 0 0 ::1:631 :::* LISTEN 1632/cupsd
tcp 0 0 :::3128 :::* LISTEN 2351/(squid)
nslookup : domain name | ip address
/etc/sysconfig/network :用于设置主机名和系统启动时是否加载网卡
/etc/service :为网络服务配置文件,用于将网络服务名转换为端口号/协议;
原文地址:http://freedom1991.blog.51cto.com/10752428/1699572