Linux Notes Lesson Tenth

Source: Internet
Author: User
Tags ping and traceroute

First, the basic knowledge of the network

1, hub (hub) work in the first layer (that is, the physical layer), it has no intelligent processing power, for it, the data is only a current, when a port of the current to the hub, it simply transmits the current to other ports, as for the other ports connected to the computer receive this data, it does not matter, Broadcast every time you send it.

2, switch (switch aka Interchange Hub) work in the second layer (that is, the data link layer), it is more intelligent than the hub, for it, the data on the network is a collection of MAC address, it can distinguish between the source MAC address and the destination MAC address in the frame, so you can establish a connection between any two ports, But the switch does not know the IP address, only know the MAC address, the switch can only narrow the conflict domain, but cannot narrow the broadcast domain, now the switch is divided into: Two layer switch, three layer switch or higher level switch. Layer three switches can also have routing capabilities, and faster forwarding rates than low-end routers. Although the third layer above the switch has the VLAN function, may also divide the broadcast domain, but each sub-broadcast domain is unable to communicate the communication, the communication between them still needs the router.

3, the router (Router) work in the third layer (that is, the network layer), it is more "smart" than the switch, it can understand the IP address in the data, if it receives a packet, it checks the IP address, if the destination address is local network is ignored, if it is the other network, The packet is forwarded to the local network, the router can isolate the broadcast domain, and the broadcast message cannot continue broadcasting through the router.

Ii. OSI seven-layer model
1, OSI model. 1 Physical media: Physical layer, Physical layer protocol, 2 link layer: Data frame, link layer protocol, 3 network layer: Packet, IP Protocol, 4 Transport layer: port for marking process (TCP,UDP, 0-65535, and Socket Socket:IP:port), 5 session Layer 6 presentation layer 7 Application Layer: Tag resources.

2, IPV4 private address a class One: 10.0.0.0~10.255.255.255, Class B 16:172.16.0.0~172.31.255.255, Class C 256:192.168.0.0~192.168.255.255, Public address IP: from 0.0.0.0–127.255.255.255, Class B IP: From 128.0.0.0–191.255.255.255, Class C IP: From 192.0.0.0-223.255.255.255, all 0: network address, All 1: Broadcast address

Third, Linux Network Properties Configuration

1, Ip/netmask , routing (host routing, network routing, default gateway), DNS server (primary DNS server, alternate DNS server), hostname, configuring Network properties (static configuration, dynamic configuration DHCP)

2 , configure IP:

User space tool: ifconfig (older tool, package name Net-tools), IP (new tool, package name Iproute2), Ifconfig is no longer used on CENTOS7, and immediate effect is not permanent.

Network Device Profile:/etc/sysconfig/network-scripts/,ifup enable interface, Ifdown shutdown interface, configure host name/ETC/RESOLV.COF, permanent effect does not take effect immediately.

Gui/tui:/etc/sysconfig/network/gui

How network devices are configured: kernel-aware Hardware device (driver), Device name: (Ethernet ETHX,ENS33), (PPP network: PPPX), (loopback: local loopback device lo)

3 , configure IP: You can use Ifconfig to display all active connections by default.

Configuration For example: (ifconfig eth0 192.168.18.23 netmask 255.255.255.0 or short format ifocnfig eth0 192.168.18.23/24) Profile field description (Device device file, Bootproto{bootp|dhcp|static|none}, Nm_controlled={yes|no}: Whether to accept NetworkManager service scripts Configure this device CENTOS6 on this option general settings No, onboot ={yes|no}: Whether this interface is activated automatically on boot, type{ethernet| Bridge}: Network interface types, IPADDR addresses, netmask subnet masks, Gateway gateways, Userctl={yes|no}: Allow normal control of this interface, peerdns={yes|no}: Do not accept DNS server addresses assigned by the DHCP server)

4 , configuring routes: Route display routing information-n number format display, add and del related parameters

<1>-net : Target network,-net net_address GW next_hop [Dev]

Example: #Route add–net 10.0.0.0/8 GW 192.168.1.254 #route –n View

#route add–net 0.0.0.0 GW 192.168.1.254

#route Add default GW 192.168,1.254 Add a default route

Delete route #route del–host 192.168.10.177, #route –n view

<2>-host : Target host,-host host_ip GW next_hop [Dev]

Example: Route add–host 192.168.1.188 GW 192.168.1.254 #route –n View

GW : Gateway, followed by device name eth0, etc., if-net 0.0.0.0 indicates that the default route destination is any address)

Add route example: Route add-net 192.168.20.0/24 GW 192.168.10.1)

Remove Route example: Route del 192.168.20.0.

5 , Route table field description (Destination: Target network or target host, Gateway: If the field 0.0.0.0 indicates that the local network does not require a gateway, Genmask: Subnet mask, Flags: (U means effective, G means the gateway can send data through the gateway to the specified network, h indicates that the host route does not need to specify the subnet mask 32 example: Route add-host 192.168.20.33 GW 192.168.10.1) Metric: Priority Ref:use Iface), Want to route information permanently valid to add Route-eth0 under/etc/sysconfig/network-script/, there are 2 formats to add the routing table (first example: 192.168.20.0 via 192.168.10.1, the second way one entry per three lines: addess0=192.168.20.0, netmask0=255.255.255.0, gateway0=192.168.10.1)

6 , DNS server address (local resolution:/etc/hosts, set DNS server/etc/resolv.conf in config file), configure whether power on automatically runs # chkconfig servername On|off, See which services start automatically: Chkconfig--list,

Iv. Network Advanced function configuration

1 , one NIC configures multiple IPs for example: Ifconfig eth0:0 192.168.146.129, you can add a configuration file ifcfg-eth0:0 (you must use static ip,device=, Bootproto={static|none}, Ipaddr=, netmask=, onboot=, Userctl =) You can also configure the network interface with System-config-network-tui

2 , ping Internet Packet Explorer Packet Internet GROPER:-C Specifies the number of messages sent,-W waits for the response time-out. Traceroute gets all the gateways that have passed from the current host to the destination host, and the MTR corresponds to ping and traceroute, netstat display network status (-t display TCP protocol,-U display UDP protocol,-l display connection status,-p display process number,- n Digital display,-a display all,-r display routing table) ethtool Display network Interface device properties-s display Device interface statistics

3 , IP (link management interface, show display management interface status For example: IP link show,set setting network interface {up |) Start or close interface such as IP link set eth0 up) (Addr Management Protocol address: Show or clear {Show | Flush} For example: IP addr show eth0, add or remove {add | del} for example: IP addr add 192.168.30.4/24 dev eth0, remove ip addr del 192.168.30.4/24 dev eth0) , (Route route management: {show | list | flush} For example: IP route list,{add | del} For example: IP route add 192.168.20.0/24 via 192.168.18.1 dev eth1)

4 , SS-like Netstat (-t displays TCP process information,-u displays UDP process information,-n displays digitally,-p displays PID,-l listens,-a all processes,-e extended information, and-m socket-related memory usage information)

Five, homework practice:

1 , scanning all the hosts in the company, online, using green display, not online, using red display, and finally show: online and not online how many hosts;

Onlinecounter=0

Offlinecounter=0

For ((i=1;i<256;i++));d o

If Ping-c 1-w 1 192.168.18. $i &>/dev/null; then

Let onlinecounter++

Echo-e "\033[32m 192.168.18. $i \033[0m"

Else

Let offlinecounter++

Echo-e "\033[31m 192.168.18. $i \033[0m"

Fi

Done

echo "Online counter: $OnlineCounter and Offline counter: $OfflineCounter"

2, prompt the user to enter an IP address, if the user entered an incorrect address, then remind them to re-enter until correct, if correct, then add to the secondary address on the eth0, to obtain the correct mask;

Read-p "Plese inport IP Address:" IPAddress

while [$ipaddress! = "" >/dev/null];d o

If ' echo ' $ipaddress | Grep-e "\< ([1-9]|[ 1-9][0-9]|1[0-9]{2}|2[0-3][0-9]) (\. ( [0-9]| [1-9] [0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])) {2}\. ([1-9]| [1-9] [0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-4]) ">/dev/null"; then

Munber= ' echo ' $ipaddress | cut-d.-f1 '

Mask=0

If [$munber-lt];then

Mask=8

elif [$munber-lt 192-a $munber-gt 127];then

Mask=16

Else

Mask=24

Fi

Ifconfig eth0:1 $ipaddress/$mask

Exit 0

Else

Read-p "You inport ipaddress error plese Input again:" IPAddress

Fi

Done

Extracurricular tasks: Nmap, NCAT, tcpdump

Linux Notes Lesson Tenth

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.