码迷,mamicode.com
首页 > 系统相关 > 详细

Linux中的涉及网络基本知识

时间:2015-09-09 14:52:06      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:linux的 网络命令和工具

Linux中的涉及网络基本知识:

            TCP/IP

                        物理层:

                        链路层:MAC  从设备到设备主机通信,MAC地址,IP<-->MAC(ARP/RARP)                        MTU

                        网络层:IP报文 从源主机到目标主机之间通信,IP地址,IP报文

                        传输层:从源主机进程到目标主机特定进程之间通信,TCP/UDP

                        应用层:        

         

 

            ISO/OSI:七层

                        1-4:通信

                        5-7:资源

                                    会话层

                                    表示层

                                    应用层

 

            TCP:有连接协议,建立逻辑连接

                        SYN, ACK, FIN, RST, PSH,URG

 

                        三次握手:

                                    SYN=1,ACK=0, FIN=0

                                    SYN=1,ACK=1, FIN=0

                                    SYN=0,ACK=1, FIN=0

 

                        四次断开:确认通讯确实需要中断

 

                        有限状态机:

 

主机:TCP/IP协议栈

 

回顾:IPV4:私有5类地址网段:

                        A10.0.0.0/8

                        B: 172.16.0.0/16,172.31.0.0/16

                        C: 192.168.0.0/24,192.168.255.0/24

                        D

                        E

 

            OSI7 layers

                        4 :

                                    TCP, UDP                  

 

            tcp三次握手:

                        1次:SYN1ACK0FIN0

                        2次:SYN=1, ACK=1,FIN=0

                        3次:SYN0ACK1FIN=0

 

            A --> B, B --> A

           

            IP首部,TCP首部

 

            VLAN:

 

Linux网络属性配置:

            IPNETMASK

            路由:

                        主机路由

                        网络路由

                        默认网关

            DNS服务器:

                        DNS服务器

                        备用DNS服务器

            主机名

 

            配置网络属性:

                        静态配置

                        动态配置:DHCP

                                    Dynamic HostConfiguration Protocol

                                   

 

            配置IP

                        用户空间工具:ifconfig(net-tools), ip (iproute2)

                        网络设备服务配置文件:/etc/sysconfig/network-scripts/

                                    主机名:/etc/resolv.conf

                        GUITUI

 

            网络设备的配置方式:

                        内核识别硬件设备:驱动

                                   

                        设备名称:

                                    以太网:ethX

                                                eth0,eth1, eth2, ...

                                    PPP网络:pppX

                                    loopback: 本地回环,lo

 

            ifconfig:

                        默认为显示所有处于激活状态的连接

                        a

 

                        ifconfig IFNAME:仅显示指定接口的信息

                        ifconfig IFNAME ADDRESS

                                    ip/mask

                                                长格式:ifconfig IFNAMEIP netmask MASK

                                                短格式:ifconfig IFNAMEIP/MASK

 

            route:

                        route:显示路由信息

                                    -n: 数字格式的地址

 

                        route add

                                    -host:目标为主机

                                                -hostHOST_IP gw NEXT_HOP [dev DEVICE]

                                    -net:目标是网络

                                                -netNET_ADDRESS gw NEXT_HOP [dev DEVICE]

 

                                                -net0.0.0.0: 表示目标为任意地址

 

                                    route add default gw GW_ADD

                       

                        route del

                                    -hostHOST_IP

                                    -netNET_ADDRESS

 

            DNS服务器地址:

                        本地解析: /etc/hosts

                        DNS服务器解析:指定DNS服务器地址

 

                        dig -t A FQDN

                                    FullQualified Domain Name

                                    www.magedu.com

 

                        dig -x IP:

                                    反解IPFQDN

 

            使用命令配置的信息直接送往内核(TCPIP协议栈)并立即生效;

 

            IPNETMASK

                        配置文件有两类(/etc/sysconfig/network-scripts):

                                    配置IP、掩码和网关:

                                                以太网:ifcfg-IFNAME

                                                PPP:ifcfg-pppX

                                    配置路由:route-IFNAME

 

                        CentOS 5:/etc/rc.d/init.d/network

                        CentOS 6:/etc/rc.d/init.d/network

                                        /etc/rc.d/init.d/NetworkManager

 

            /etc/rc.d/init.d//etc/init.d/*

                        SysV风格的脚本:多数脚本都用于控制Linux的后台进程,接受参数{start|stop|restart|status}

                       

                        # /etc/init.d/networkstart

                        # service network start           

                       

                        配置某服务是否开机自动运行:

                                    # chkconfigSRVNAME onoff

                        查看哪些服务开机自动运行:

                                    # chkconfig--list

 

 

            ifcfg-IFNAME配置文件的格式:

                    DEVICEIFNAME: 此配置文件所关联到的设备,设备名称要与本文件名ifcfg-后面保持一致;

                        BOOTPROTO{bootp|dhcp|static|none}

                        HWADDR=00:11:22:33:44:55:66:当前设备的MAC地址;

                        NM_CONTROLLED={yes|no}: 是否接受NetworkManager服务脚本来配置此设备;

                        ONBOOT={yes|no}: 是否在开机过程中,自动激活此接口

                        TYPE{Ethernet|Bridge}:网络接口类型

                        UUID

                        IPADDR

                        NETMASK

                        GATEWAY

                        DNS1

                        DNS2

                        IPV6INIT{yes|no}

                        USERCTL={yes|no}: 是否允许普通用控制此接口

                       

                        PEERDNS{yes|no}: 不接受DHCP服务器指派的DNS服务器地址

 

            route-IFNAME:

                        配置文件的格式1:每行一个路由条目

                                    DESTINATIONvia NETX_HOP

 

                        配置文件格式2: 每三行一个路由条目

                                    ADDRESS#=DESTINATION

                                    NETMASK#=MASK

                                    GATEWAY#=GW

 

            如何配置主机名:

                        hostname

                        hostname HOSTNAME

 

                        配置文件:/etc/sysconfig/network

                                    HOSTNAME=主机名

 

 

            如何在一个网络接口配置多个IP地址:

 

                        通过网络接口的别名来实现:IFNAME:#

                                    ens33,ens33:0, ens33:1, ens33:2

                                    eth0eth0:0, eth0:1

 

                        命令配置:立即生效

                                    ifconfigIFALIAS IP

 

                        配置文件配置:别名不支持使用DHCP进行配置

                                    ifcfg-IFALIAS

                                                DEVICE=IFALIAS

                                                BOOTPROTO={static|none}

                                                IPADDR=

                                                NETMASK=

                                                ONBOOT=

                                                USERCTL=

 

 

            TUI或者GUI

                        TUI:system-config-network-tui

                        GUIsystem-config-network-gui

 

                        setup --> NetworkConfiguration

 

 

                        修改的结果会保存至相应的网络接口的配置文件ifcfg-IFNAME,因此,不会立即生效;

 

            网络管理相关的工具:

                        ping: ICMP

                                    ping[option]... IP

                                                -c#: 报文的个数

                                                -Wtimeout: 等待响应报文的超时时长;

 

                        traceroute:

                                    tracerouteHOST

                                                获取从当前主机到达目标主机所经由的所有网关;

 

                        mtr HOST

 

                        netstat: (ss)

                                    -t: tcp协议相关

                                    -u: udp协议相关

                                    -n: 显示数字格式的地址

                                    -l: listen,显示处于监听状态的连接

                                                -tunl

                                    -a: 所有状态的连接

                                                -tan

                                    -p: 显示会话中的进程程序名及进程号

                                    -r: routing,显示路由表

                                                -rn

 

                                    名称解析:

                                                FQDN<==> IP

                                                ServiceName <==> PORT

 

            显示网络接口设备的属性信息:

                        ethtool IFNAME

                                    -S: 显示设备接口的统计数据

 

            课外任务:nmap, ncat,tcpdump

 

            ip命令:

                        ip link : 管理接口

                                    show[IFNAME]

                                    set IFNAME{up|down}

                                                multicast{on|off}

 

                                    # ifconfigIFNAME {up|down}

                                    # ifupIFNAME

                                    # ifdownIFNAME

 

                        ip addr: 管理协议地址

                                    ip addr{show|flush} [dev DEVICE]

 

                                    ip addr{add|del} ADDRESS dev DEVICE  [label IFALIAS][broadcast BCAST_ADDRESS]

 

                                                #ifconfig IFNAME ADDRESS broadcast BCAST_ADDRESS

 

                        ip route: 管理路由

                                    ip routelist

 

                                    ip routeflush

 

                                    ip route addDESTINATION [via NEXT_HOP] [src SOURCE_ADDRESS] [dev DEVICE]

                                    ip route delDESTINATION

 

命令总结:ifconfig, ifup,ifdown, route, netstat, ping, traceroute, mtr, ethtool, setup, dig, ip, ss

           

            ss:

                        -t: tcp

                        -u: udp

                        -p: process

                        -l: listening

                        -n: numeric

                        -a: all

                        -e: 扩展信息

                        -m: 套接字相关的内存使用信息

                        -o state{established,fin_wait_1, fin_wait_2, listening}

                                    ‘( dport=   or sport =  )‘

                                    只显示指定状态的连接,还可以指定过滤条件

【网络信息及设置命令Linux Network Commands】

  COMMAND DESCRIPTION    


    dhclient -v /Sudo dhclient -v -r     //let‘s manually release our address with -r. Let‘s keep the -v option in there so we can see what‘s going on.

    netstat -tulpn      Show Linux network ports with process ID‘s (PIDs)

    watch ss -stplu     Watch TCP, UDP open ports in real time with socket summary.

    lsof -i       Show established connections.

    macchanger -m MACADDR INTR      Change MAC address on KALI Linux.

    ifconfig -a 

    ifconfig eth0 192.168.2.1/24      Set IP address in Linux.

    ifconfig eth0:1 192.168.2.3/24        Add IP address to existing network interface in Linux.

    ifconfig eth0 hw ether MACADDR        Change MAC address in Linux using ifconfig.

    ifconfig eth0 mtu 1500        Change MTU size Linux using ifconfig, change 1500 to your desired MTU.

    dig -x 192.168.1.1      Dig reverse lookup on an IP address.

    host 192.168.1.1        Reverse lookup on an IP address, in case dig is not installed.

    dig @192.168.2.2 domain.com -t AXFR       Perform a DNS zone transfer using dig.

    host -l domain.com nameserver       Perform a DNS zone transfer using host.

    nbtstat -A x.x.x.x      Get hostname for IP address.

    ip addr add 192.168.2.22/24 dev eth0        Adds a hidden IP address to Linux, does not show up when performing an ifconfig.

    ip address 

    tcpkill -9 host google.com      Blocks access to google.com from the host machine.

    echo "1" > /proc/sys/net/ipv4/ip_forward        Enables IP forwarding, turns Linux box into a router - handy for routing traffic through a box.

    echo "8.8.8.8" > /etc/resolv.conf       Use Google DNS.




网络工具

1.  ping:通过ICMP回应/回复报文来检查远端主机的端到端连接性(RTT延时,抖动,丢包)。用来检查系统状态和可连接性很不错。

2.  phping:网络扫描和检测工具,可以产生ICMP/TCP/UDPping数据包。常常用于高级端口扫描,防火墙测试,手动MTU路径发现和碎片测试。

3.  traceroute:通过TTL限定的ICMP/UDP/TCP侦测包来发现从本地主机到远端目标主机之间的第三层转发路径。用来调试网络连接性和路由问题。

4.  mtrtraceroute的一个变种,能根据运行时统计数据整理出每一跳的包丢失/抖动。用来评估路由路径延时很不错。

5.  netcat/socatTCP/IP网络里的瑞士***,可以读/ TCP/UDP 协议字节流。用来调试防火墙策略和服务可用性很不错。

6.  digDNS调试工具,可以生成正向查询,反向查询,搜索域名服务器,检查CNAMEMX和其他DNS记录。可以在侦错的时候查询特定的DNS服务器。

7.  nslookup:另外一个DNS检查/调试工具。支持所有DNS查询和记录。可以查询特定DNS服务器。

8.  dnsyo:一个DNS测试工具,通过对全世界1500个不同网络中的大量开放解析器执行DNS查询来测试DNS传输。

9.  lsof:显示进程打开的文件信息(例如,普通文件,管道或套接字)。用来监视网络连接很不错。

10.               iftop:一个基于ncurses的命令行界面应用,可以实时监视各个网络物理接口上的网络连接和带宽占用。用来记录霸占带宽的应用、用户、目的地和端口等很不错。

11.               netstat:一个网络统计工具,可以显示状态以及统计信息,当前网络连接(TCP/UDP端口,IP地址)、路由表、TX/RX traffic以及网络协议。用来做网络相关诊断和性能调试很不错。

12.               tcpdump:一个常用的基于libpcap抓包库的包侦测工具。可以按伯克利包过滤器格式定义抓包条件

13.               tshark:另一个命令行抓包工具,和它的GUI版本Wireshark完全兼容。支持1000种协议而且这个列表还在增加。用来调试、分析和保存实时网络封包信息很不错。

14.               ip:一个多功能的命令行网络工具,是iproute2包的一部分。可以检查和修改路由表、网络设备状态以及IP隧道设置。用来查看路由表、增加/删除静态路由、配置网络接口、以及调试路由问题很有用。

15.               ifup/ifdown:用来激活和关闭特定的网络接口。经常用于重启整个网络服务。

16.               autossh:一个能建立SSH连接并在断线后自动重新连接的程序。用来创建长时间保持的穿越严格企业网络的SSH隧道很有用。

17.               iperf:一个网络测试工具,通过在发送自定义TCP/UDP数据流来衡量主机间双向最大吞吐量。

18.               elinks/lynx:为基于命令行的服务器环境下使用的基于文字的网页浏览器。

课外任务:nmap, netcat, tcpdump

Nmap(Network Mapper) is a security scanner originally written by Gordon Lyon (alsoknown by his pseudonym Fyodor Vaskovich)[1] used to discover hosts and serviceson a computer network, thus creating a "map" of the network. Toaccomplish its goal, Nmap sends specially crafted packets to the target host andthen analyzes the responses. 发现特定网段下存在hosts 


NmapExamples : nmap-sP 10.0.0.0/24  //Pingscans the network, listing machines that respond to ping.


Netcat(often abbreviated to nc) is a computer networking service for reading from andwriting to network connections using TCP or UDP. Netcat is designed to be adependable back-end that can be used directly or easily driven by otherprograms and scripts. At the same time, it is a feature-rich network debuggingand investigation tool, since it can produce almost any kind of correlation itsuser could need and has a number of built-in capabilities.

Itslist of features includes port scanning, transferring files, and portlistening, and it can be used as a backdoor.

扫描host端口情况


tcpdump is a common packet analyzer that runs under the command line. It allows the user to display TCP/IP and other packets being transmitted or received over anetwork to which the computer is attached. 


查找发出ip到目的ip端口的数据包


#TCP traffic from 10.5.2.3 destined for port 3389 

tcpdump-nnvvS src 10.5.2.3 and dst port 3389






本文出自 “IT_working” 博客,请务必保留此出处http://weine100.blog.51cto.com/2152945/1693079

Linux中的涉及网络基本知识

标签:linux的 网络命令和工具

原文地址:http://weine100.blog.51cto.com/2152945/1693079

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!