nmap -sT linux4you.tk
Category Archives: Linux networking
TCP port 0 usage
Using port 0 tells the OS to automatically assign a port. It just checks if you’ve given it zero and if so, gives you a free port instead.
TCP SYN all ports from 1 to 65535
nmap -v -sS -sU -PN -p 1-65535 linux4you.tk
It will take some time.
Just-ping alternative
If you want use just ping alternative, you can do this there http://cloudmonitor.ca.com/en/
Its still free.
ifconfig cheatsheet
purpose | net-tools | new iproute2 replacement |
---|---|---|
Address and link configuration | ifconfig | ip addr ip link |
Routing tables | route | ip route |
Neighbors | arp | ip neigh |
Tunnels | iptunnel | ip tunnel |
Multicast | ipmaddr | ip maddr |
Statistics | netstat | ss |
function | iproute2 command |
---|---|
show ip addresses |
ip a ip address show ip addr show dev eth0 ip a sh eth0 |
add/delete ip addresses |
ip address add 192.0.2.1/24 dev eth0 ip addr del 192.0.2.2/24 dev eth0 for ip in {2..254}; do ip a a 10.1.100.$ip dev eth0; done |
show interface statistics |
ip -s link ls eth0 |
show links/devices |
ip link show ip link sh eth0 |
set link/device state |
ip link set eth0 up ip link s gre01 down |
show routing table |
ip route ip ro show dev gre01 |
add new route |
ip route add 10.2.2.128/27 dev gre01 |
add default route |
ip route add default via 192.168.1.1 |
change existing default route |
ip route chg default via 192.168.1.2 |
delete default route |
ip route del default |
add/delete a new tunnels | GRE Tunnel:
ip tunnel add gre01 mode gre local 10.1.1.1 remote 20.2.2.1 ttl 255 IPIP Tunnel: ip tunl a ipip01 mode ipip local 10.1.1.1 remote 20.2.2.1 ttl 255 ip tunnel del gre01 |
show tunnels |
ip tunnel show |
show tunnel statistics |
ip -s tunl ls gre01 |
view arp cache table |
ip neigh show |
add/delete arp entries |
ip neighbor add 10.2.2.2 dev eth0 ip neigh del 10.2.2.1 dev eth0 |
listening sockets |
ss -l |
listening processes |
ss -p |
linux socets
ss command is used to show socket statistics. It can display stats for PACKET sockets, TCP sockets, UDP sockets, DCCP sockets, RAW sockets, Unix domain sockets, and much more. It allows showing information similar to netstatcommand. It can display more TCP and state information than other tools. It is a new, incredibly useful and faster (as compare to netstat) tool for tracking TCP connections and sockets. SS can provide information about:
- All TCP sockets.
- All UDP sockets.
- All established ssh / ftp / http / https connections.
- All local processes connected to X server.
- Filtering by state (such as connected, synchronized, SYN-RECV, SYN-SENT,TIME-WAIT), addresses and ports.
- All the tcp sockets in state FIN-WAIT-1 and much more.
cidr ip block
This is very useful if you can't remember netmask or how much IP's are usable and belongs IP block.
IP/CIDR | Δ to last IP addr | Mask | Hosts (*) | Size | Notes |
---|---|---|---|---|---|
a.b.c.d/32 | +0.0.0.0 | 255.255.255.255 | 1 | 1/256 C | |
a.b.c.d/31 | +0.0.0.1 | 255.255.255.254 | 2 | 1/128 C | d = 0 … (2n) … 254 |
a.b.c.d/30 | +0.0.0.3 | 255.255.255.252 | 4 | 1/64 C | d = 0 … (4n) … 252 |
a.b.c.d/29 | +0.0.0.7 | 255.255.255.248 | 8 | 1/32 C | d = 0 … (8n) … 248 |
a.b.c.d/28 | +0.0.0.15 | 255.255.255.240 | 16 | 1/16 C | d = 0 … (16n) … 240 |
a.b.c.d/27 | +0.0.0.31 | 255.255.255.224 | 32 | ⅛ C | d = 0 … (32n) … 224 |
a.b.c.d/26 | +0.0.0.63 | 255.255.255.192 | 64 | ¼ C | d = 0, 64, 128, 192 |
a.b.c.d/25 | +0.0.0.127 | 255.255.255.128 | 128 | ½ C | d = 0, 128 |
a.b.c.0/24 | +0.0.0.255 | 255.255.255.000 | 256 | 1 C | |
a.b.c.0/23 | +0.0.1.255 | 255.255.254.000 | 512 | 2 C | c = 0 … (2n) … 254 |
a.b.c.0/22 | +0.0.3.255 | 255.255.252.000 | 1,024 | 4 C | c = 0 … (4n) … 252 |
a.b.c.0/21 | +0.0.7.255 | 255.255.248.000 | 2,048 | 8 C | c = 0 … (8n) … 248 |
a.b.c.0/20 | +0.0.15.255 | 255.255.240.000 | 4,096 | 16 C | c = 0 … (16n) … 240 |
a.b.c.0/19 | +0.0.31.255 | 255.255.224.000 | 8,192 | 32 C | c = 0 … (32n) … 224 |
a.b.c.0/18 | +0.0.63.255 | 255.255.192.000 | 16,384 | 64 C | c = 0, 64, 128, 192 |
a.b.c.0/17 | +0.0.127.255 | 255.255.128.000 | 32,768 | 128 C | c = 0, 128 |
a.b.0.0/16 | +0.0.255.255 | 255.255.000.000 | 65,536 | 256 C = 1 B | |
a.b.0.0/15 | +0.1.255.255 | 255.254.000.000 | 131,072 | 2 B | b = 0 … (2n) … 254 |
a.b.0.0/14 | +0.3.255.255 | 255.252.000.000 | 262,144 | 4 B | b = 0 … (4n) … 252 |
a.b.0.0/13 | +0.7.255.255 | 255.248.000.000 | 524,288 | 8 B | b = 0 … (8n) … 248 |
a.b.0.0/12 | +0.15.255.255 | 255.240.000.000 | 1,048,576 | 16 B | b = 0 … (16n) … 240 |
a.b.0.0/11 | +0.31.255.255 | 255.224.000.000 | 2,097,152 | 32 B | b = 0 … (32n) … 224 |
a.b.0.0/10 | +0.63.255.255 | 255.192.000.000 | 4,194,304 | 64 B | b = 0, 64, 128, 192 |
a.b.0.0/9 | +0.127.255.255 | 255.128.000.000 | 8,388,608 | 128 B | b = 0, 128 |
a.0.0.0/8 | +0.255.255.255 | 255.000.000.000 | 16,777,216 | 256 B = 1 A | |
a.0.0.0/7 | +1.255.255.255 | 254.000.000.000 | 33,554,432 | 2 A | a = 0 … (2n) … 254 |
a.0.0.0/6 | +3.255.255.255 | 252.000.000.000 | 67,108,864 | 4 A | a = 0 … (4n) … 252 |
a.0.0.0/5 | +7.255.255.255 | 248.000.000.000 | 134,217,728 | 8 A | a = 0 … (8n) … 248 |
a.0.0.0/4 | +15.255.255.255 | 240.000.000.000 | 268,435,456 | 16 A | a = 0 … (16n) … 240 |
a.0.0.0/3 | +31.255.255.255 | 224.000.000.000 | 536,870,912 | 32 A | a = 0 … (32n) … 224 |
a.0.0.0/2 | +63.255.255.255 | 192.000.000.000 | 1,073,741,824 | 64 A | a = 0, 64, 128, 192 |
a.0.0.0/1 | +127.255.255.255 | 128.000.000.000 | 2,147,483,648 | 128 A | a = 0, 128 |
0.0.0.0/0 | +255.255.255.255 | 000.000.000.000 | 4,294,967,296 | 256 A |
Also please look there: Netmask Netmask (binary) CIDR Notes _____________________________________________________________________________ 255.255.255.255 11111111.11111111.11111111.11111111 /32 Host (single addr) 255.255.255.254 11111111.11111111.11111111.11111110 /31 Unuseable 255.255.255.252 11111111.11111111.11111111.11111100 /30 2 useable 255.255.255.248 11111111.11111111.11111111.11111000 /29 6 useable 255.255.255.240 11111111.11111111.11111111.11110000 /28 14 useable 255.255.255.224 11111111.11111111.11111111.11100000 /27 30 useable 255.255.255.192 11111111.11111111.11111111.11000000 /26 62 useable 255.255.255.128 11111111.11111111.11111111.10000000 /25 126 useable 255.255.255.0 11111111.11111111.11111111.00000000 /24 "Class C" 254 useable 255.255.254.0 11111111.11111111.11111110.00000000 /23 2 Class C's 255.255.252.0 11111111.11111111.11111100.00000000 /22 4 Class C's 255.255.248.0 11111111.11111111.11111000.00000000 /21 8 Class C's 255.255.240.0 11111111.11111111.11110000.00000000 /20 16 Class C's 255.255.224.0 11111111.11111111.11100000.00000000 /19 32 Class C's 255.255.192.0 11111111.11111111.11000000.00000000 /18 64 Class C's 255.255.128.0 11111111.11111111.10000000.00000000 /17 128 Class C's 255.255.0.0 11111111.11111111.00000000.00000000 /16 "Class B" 255.254.0.0 11111111.11111110.00000000.00000000 /15 2 Class B's 255.252.0.0 11111111.11111100.00000000.00000000 /14 4 Class B's 255.248.0.0 11111111.11111000.00000000.00000000 /13 8 Class B's 255.240.0.0 11111111.11110000.00000000.00000000 /12 16 Class B's 255.224.0.0 11111111.11100000.00000000.00000000 /11 32 Class B's 255.192.0.0 11111111.11000000.00000000.00000000 /10 64 Class B's 255.128.0.0 11111111.10000000.00000000.00000000 /9 128 Class B's 255.0.0.0 11111111.00000000.00000000.00000000 /8 "Class A" 254.0.0.0 11111110.00000000.00000000.00000000 /7 252.0.0.0 11111100.00000000.00000000.00000000 /6 248.0.0.0 11111000.00000000.00000000.00000000 /5 240.0.0.0 11110000.00000000.00000000.00000000 /4 224.0.0.0 11100000.00000000.00000000.00000000 /3 192.0.0.0 11000000.00000000.00000000.00000000 /2 128.0.0.0 10000000.00000000.00000000.00000000 /1 0.0.0.0 00000000.00000000.00000000.00000000 /0 IP space Net Host Total Net Addr Addr Addr Number Class Range NetMask Bits Bits of hosts ---------------------------------------------------------- A 0-127 255.0.0.0 8 24 16777216 (i.e. 114.0.0.0) B 128-191 255.255.0.0 16 16 65536 (i.e. 150.0.0.0) C 192-254 255.255.255.0 24 8 256 (i.e. 199.0.0.0) D 224-239 (multicast) E 240-255 (reserved) F 208-215 255.255.255.240 28 4 16 G 216/8 ARIN - North America G 217/8 RIPE NCC - Europe G 218-219/8 APNIC H 220-221 255.255.255.248 29 3 8 (reserved) K 222-223 255.255.255.254 31 1 2 (reserved) (ref: RFC1375 & http://www.iana.org/assignments/ipv4-address-space ) ( http://www.iana.org/numbers.htm ) ---------------------------------------------------------- The current list of special use prefixes: 0.0.0.0/8 127.0.0.0/8 192.0.2.0/24 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 169.254.0.0/16 all D/E space (ref: RFC1918 http://www.rfc-editor.org/rfc/rfc1918.txt ) ( or ftp://ftp.isi.edu/in-notes/rfc1918.txt ) (rfc search: http://www.rfc-editor.org/rfcsearch.html ) ( http://www.ietf.org/ietf/1id-abstracts.txt ) ( http://www.ietf.org/shadow.html ) Martians: (updates at: www.iana.org/assignments/ipv4-address-space ) no ip source-route access-list 100 deny ip host 0.0.0.0 any deny ip 0.0.0.0 0.255.255.255 any log ! antispoof deny ip 0.0.0.0 0.255.255.255 0.0.0.0 255.255.255.255 ! antispoof deny ip any 255.255.255.128 0.0.0.127 ! antispoof deny ip host 0.0.0.0 any log ! antispoof deny ip host [router intf] [router intf] ! antispoof deny ip xxx.xxx.xxx.0 0.0.0.255 any log ! lan area deny ip 0/8 0.255.255.255 any log ! IANA - Reserved deny ip 1/8 0.255.255.255 any log ! IANA - Reserved deny ip 2/8 0.255.255.255 any log ! IANA - Reserved deny ip 5/8 0.255.255.255 any log ! IANA - Reserved deny ip 7/8 0.255.255.255 any log ! IANA - Reserved deny ip 10.0.0.0 0.255.255.255 any log ! IANA - Private Use deny ip 23/8 0.255.255.255 any log ! IANA - Reserved deny ip 27/8 0.255.255.255 any log ! IANA - Reserved deny ip 31/8 0.255.255.255 any log ! IANA - Reserved deny ip 36-37/8 0.255.255.255 any log ! IANA - Reserved deny ip 39/8 0.255.255.255 any log ! IANA - Reserved deny ip 41-42/8 0.255.255.255 any log ! IANA - Reserved deny ip 50/8 0.255.255.255 any log ! IANA - Reserved deny ip 58-60/8 0.255.255.255 any log ! IANA - Reserved deny ip 69-79/8 0.255.255.255 any log ! IANA - Reserved deny ip 82-95/8 0.255.255.255 any log ! IANA - Reserved deny ip 96-126/8 0.255.255.255 any log ! IANA - Reserved deny ip 127/8 0.255.255.255 any log ! IANA - Reserved deny ip 169.254.0.0 0.0.255.255 any log ! link-local network deny ip 172.16.0.0 0.15.255.255 any log ! reserved deny ip 192.168.0.0 0.0.255.255 any log ! reserved deny ip 192.0.2.0 0.0.0.255 any log ! test network deny ip 197/8 0.255.255.255 any log ! IANA - Reserved deny ip 220/8 0.255.255.255 any log ! IANA - Reserved deny ip 222-223/8 0.255.255.255 any log ! IANA - Reserved deny ip 224.0.0.0 31.255.255.255 any log ! multicast deny ip 224.0.0.0 15.255.255.255 any log ! unless MBGP-learned routes deny ip 224-239/8 0.255.255.255 any log ! IANA - Multicast deny ip 240-255/8 0.255.255.255 any log ! IANA - Reserved filtered source addresses 0/8 ! broadcast 10/8 ! RFC 1918 private 127/8 ! loopback 169.254.0/16 ! link local 172.16.0.0/12 ! RFC 1918 private 192.0.2.0/24 ! TEST-NET 192.168.0/16 ! RFC 1918 private 224.0.0.0/4 ! class D multicast 240.0.0.0/5 ! class E reserved 248.0.0.0/5 ! reserved 255.255.255.255/32 ! broadcast ARIN administrated blocks: (http://www.arin.net/regserv/IPStats.html) 24.0.0.0/8 (portions of) 63.0.0.0/8 64.0.0.0/8 65.0.0.0/8 66.0.0.0/8 196.0.0.0/8 198.0.0.0/8 199.0.0.0/8 200.0.0.0/8 204.0.0.0/8 205.0.0.0/8 206.0.0.0/8 207.0.0.0/8 208.0.0.0/8 209.0.0.0/8 216.0.0.0/8 ---------------------------------------------------------- well known ports: (rfc1700.txt) www.iana.org/assignments/port-numbers protocol numbers: www.iana.org/assignments/protocol-numbers www.iana.org/numbers.htm ICMP(Types/Codes) Testing Destination Reachability & Status (0/0) Echo-Reply (8/0) Echo Unreachable Destinations (3/0) Network Unreachable (3/1) Host Unreachable (3/2) Protocol Unreachable (3/3) Port Unreachable (3/4) Fragmentaion Needed and DF set (Pkt too big) (3/5) Source Route Failed (3/6) Network Unknown (3/7) Host Unknown (3/9) DOD Net Prohibited (3/10) DOD Host Prohibited (3/11) Net TOS Unreachable (3/12) Host TOS Unreachable (3/13) Administratively Prohibited (3/14) Host Precedence Unreachable (3/15) Precedence Unreachable Flow Control (4/0) Source-Quench [RFC 1016] Route Change Requests from Gateways (5/0) Redirect Datagrams for the Net (5/1) Redirect Datagrams for the Host (5/2) Redirect Datagrams for the TOS and Net (5/3) Redirect Datagrams for the TOS and Host Router (6/-) Alternate-Address (9/0) Router-Advertisement (10/0) Router-Solicitation Detecting Circular or Excessively Long Routes (11/0) Time to Live Count Exceeded (11/1) Fragment Reassembly Time Exceeded Reporting Incorrect Datagram Headers (12/0) Parameter-Problem (12/1) Option Missing (12/2) No Room for Option Clock Synchronization and Transit Time Estimation (13/0) Timestamp-Request (14/0) Timestamp-Reply Obtaining a Network Address (RARP Alternative) (15/0) Information-Request (16/0) Information-Reply Obtaining a Subnet Mask [RFC 950] (17/0) Address Mask-Request (18/0) Address Mask-Reply Other (30/0) Traceroute (31/0) Conversion-Error (32/0) Mobile-Redirect Ref: [RFC 792] [RFC 896] [RFC 950] [RFC 1016] www.cisco.com/univercd/cc/td/doc/product/lan/cat6000/sw_5_3/cofigide/qos.htm#19774 Decimal system Prefix's Factor Exponent Prefix --------------------------------------------------- 1 000 000 000 000 000 000 000 000...10^24....yotta 1 000 000 000 000 000 000 000...10^21....zetta 1 000 000 000 000 000 000...10^18....exa 1 000 000 000 000 000...10^15....peta 1 000 000 000 000...10^12....tera 1 000 000 000...10^9.....giga 1 000 000...10^6.....mega 1 000...10^3.....kilo 100...10^2.....hecto 10...10^1.....deka 0.1...10^-1....deci 0.01...10^-2....centi 0.001...10^-3....milli 0.000 001...10^-6....micro 0.000 000 001...10^-9....nano 0.000 000 000 001...10^-12...pico 0.000 000 000 000 001...10^-15...femto 0.000 000 000 000 000 001...10^-18...atto 0.000 000 000 000 000 000 001...10^-21...zepto 0.000 000 000 000 000 000 000 001...10^-24...yocto --------------------------------------------------- Convert Fahrenheit <> Celsius: Celsius = (Fahrenheit - 32) / 1.8 Fahrenheit = (Celsius * 1.8) + 32
linux ip command
ip – show / manipulate routing, devices, policy routing and tunnels. Yes its true and I think all sysadmins should know how to use this command and feel its power. 😀 Yes ifconfig is simple, but I far as I know ifconfig is deprecated.
ip [ OPTIONS ] OBJECT { COMMAND | help }
OBJECT := { link | addr | addrlabel | route | rule | neigh | tunnel | maddr | mroute | monitor }
OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] | -f[amily] { inet | inet6 | ipx | dnet | link } | -o[neline] }
ip link set DEVICE { up | down | arp { on | off } |
promisc { on | off } |
allmulticast { on | off } |
dynamic { on | off } |
multicast { on | off } |
txqueuelen PACKETS |
name NEWNAME |
address LLADDR | broadcast LLADDR |
mtu MTU |
netns PID |
alias NAME |
vf NUM [ mac LLADDR ] [ vlan VLANID [ qos VLAN-QOS ] ] [ rate TXRATE ] }
ip link show [ DEVICE ]
ip addr { add | del } IFADDR dev STRING
ip addr { show | flush } [ dev STRING ] [ scope SCOPE-ID ] [ to PREFIX ] [ FLAG-LIST ] [ label PATTERN ]
IFADDR := PREFIX | ADDR peer PREFIX [ broadcast ADDR ] [ anycast ADDR ] [ label STRING ] [ scope SCOPE-ID ]
SCOPE-ID := [ host | link | global | NUMBER ]
FLAG-LIST := [ FLAG-LIST ] FLAG
FLAG := [ permanent | dynamic | secondary | primary | tentative | deprecated ]
ip addrlabel { add | del } prefix PREFIX [ dev DEV ] [ label NUMBER ]
ip addrlabel { list | flush }
ip route { list | flush } SELECTOR
ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ]
ip route { add | del | change | append | replace | monitor } ROUTE
SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ]
ROUTE := NODE_SPEC [ INFO_SPEC ]
NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ]
INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] …
NH := [ via ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS
OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ rtt TIME ] [ rttvar TIME ] [ window NUMBER ] [ cwnd NUMBER ] [ initcwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ] [ rto_min TIME ] [ initrwnd NUMBER ]
TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ]
TABLE_ID := [ local| main | default | all | NUMBER ]
SCOPE := [ host | link | global | NUMBER ]
FLAGS := [ equalize ]
NHFLAGS := [ onlink | pervasive ]
RTPROTO := [ kernel | boot | static | NUMBER ]
ip rule [ list | add | del | flush ] SELECTOR ACTION
SELECTOR := [ from PREFIX ] [ to PREFIX ] [ tos TOS ] [ fwmark FWMARK[/MASK] ] [ dev STRING ] [ pref NUMBER ]
ACTION := [ table TABLE_ID ] [ nat ADDRESS ] [ prohibit | reject | unreachable ] [ realms [SRCREALM/]DSTREALM ]
TABLE_ID := [ local | main | default | NUMBER ]
ip neigh { add | del | change | replace } { ADDR [ lladdr LLADDR ] [ nud { permanent | noarp | stale | reachable } ] | proxy ADDR } [ dev DEV ]
ip neigh { show | flush } [ to PREFIX ] [ dev DEV ] [ nud STATE ]
ip tunnel { add | change | del | show | prl } [ NAME ]
[ mode MODE ] [ remote ADDR ] [ local ADDR ]
[ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ] ]
[ encaplimit ELIM ] [ ttl TTL ]
[ tos TOS ] [ flowlabel FLOWLABEL ]
[ prl-default ADDR ] [ prl-nodefault ADDR ] [ prl-delete ADDR ]
[ [no]pmtudisc ] [ dev PHYS_DEV ] [ dscp inherit ]
MODE := { ipip | gre | sit | isatap | ip6ip6 | ipip6 | any }
ADDR := { IP_ADDRESS | any }
TOS := { NUMBER | inherit }
ELIM := { none | 0..255 }
TTL := { 1..255 | inherit }
KEY := { DOTTED_QUAD | NUMBER }
TIME := NUMBER[s|ms|us|ns|j]
ip maddr [ add | del ] MULTIADDR dev STRING
ip maddr show [ dev STRING ]
ip mroute show [ PREFIX ] [ from PREFIX ] [ iif DEVICE ]
ip monitor [ all | LISTofOBJECTS ]
ip xfrm XFRM_OBJECT { COMMAND }
XFRM_OBJECT := { state | policy | monitor }
ip xfrm state { add | update } ID [ XFRM_OPT ] [ mode MODE ]
[ reqid REQID ] [ seq SEQ ] [ replay-window SIZE ]
[ flag FLAG-LIST ] [ encap ENCAP ] [ sel SELECTOR ]
[ LIMIT-LIST ]
ip xfrm state allocspi ID [ mode MODE ] [ reqid REQID ] [ seq SEQ ] [ min SPI max SPI ]
ip xfrm state { delete | get } ID
ip xfrm state { deleteall | list } [ ID ] [ mode MODE ]
[ reqid REQID ] [ flag FLAG_LIST ]
ip xfrm state flush [ proto XFRM_PROTO ]
ip xfrm state count
ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM_PROTO ] [ spi SPI ]
XFRM_PROTO := [ esp | ah | comp | route2 | hao ]
MODE := [ transport | tunnel | ro | beet ] (default=transport)
FLAG-LIST := [ FLAG-LIST ] FLAG
FLAG := [ noecn | decap-dscp | wildrecv ]
ENCAP := ENCAP-TYPE SPORT DPORT OADDR
ENCAP-TYPE := espinudp | espinudp-nonike
ALGO-LIST := [ ALGO-LIST ] | [ ALGO ]
ALGO := ALGO_TYPE ALGO_NAME ALGO_KEY
ALGO_TYPE := [ enc | auth | comp ]
SELECTOR := src ADDR[/PLEN] dst ADDR[/PLEN] [ UPSPEC ] [ dev DEV ]
UPSPEC := proto PROTO [[ sport PORT ] [ dport PORT ] |
[ type NUMBER ] [ code NUMBER ]]
LIMIT-LIST := [ LIMIT-LIST ] | [ limit LIMIT ]
LIMIT := [ [time-soft|time-hard|time-use-soft|time-use-hard] SECONDS ] | [ [byte-soft|byte-hard] SIZE ] |
[ [packet-soft|packet-hard] COUNT ]
ip xfrm policy { add | update } dir DIR SELECTOR [ index INDEX ]
[ ptype PTYPE ] [ action ACTION ] [ priority PRIORITY ]
[ LIMIT-LIST ] [ TMPL-LIST ]
ip xfrm policy { delete | get } dir DIR [ SELECTOR | index INDEX ]
[ ptype PTYPE ]
ip xfrm policy { deleteall | list } [ dir DIR ] [ SELECTOR ]
[ index INDEX ] [ action ACTION ] [ priority PRIORITY ]
ip xfrm policy flush [ ptype PTYPE ]
ip xfrm count
PTYPE := [ main | sub ] (default=main)
DIR := [ in | out | fwd ]
SELECTOR := src ADDR[/PLEN] dst ADDR[/PLEN] [ UPSPEC ] [ dev DEV ]
UPSPEC := proto PROTO [ [ sport PORT ] [ dport PORT ] |
[ type NUMBER ] [ code NUMBER ] ]
ACTION := [ allow | block ] (default=allow)
LIMIT-LIST := [ LIMIT-LIST ] | [ limit LIMIT ]
LIMIT := [ [time-soft|time-hard|time-use-soft|time-use-hard] SECONDS ] | [ [byte-soft|byte-hard] SIZE ] |
[packet-soft|packet-hard] NUMBER ]
TMPL-LIST := [ TMPL-LIST ] | [ tmpl TMPL ]
TMPL := ID [ mode MODE ] [ reqid REQID ] [ level LEVEL ]
ID := [ src ADDR ] [ dst ADDR ] [ proto XFRM_PROTO ] [ spi SPI ]
XFRM_PROTO := [ esp | ah | comp | route2 | hao ]
MODE := [ transport | tunnel | beet ] (default=transport)
LEVEL := [ required | use ] (default=required)
ip xfrm monitor [ all | LISTofOBJECTS ]
Options
-V, -Version
print the version of the ip utility and exit.
-s, -stats, -statistics
output more information. If the option appears twice or more, the amount of information increases. As a rule, the information is statistics or some time values.
-f, -family
followed by protocol family identifier: inet, inet6 or link ,enforce the protocol family to use. If the option is not present, the protocol family is guessed from other arguments. If the rest of the command line does not give enough information to guess the family, ip falls back to the default one, usually inet or any. link is a special family identifier meaning that no networking protocol is involved.
-4
shortcut for -family inet.
-6
shortcut for -family inet6.
-0
shortcut for -family link.
-o, -oneline
output each record on a single line, replacing line feeds with the ” character. This is convenient when you want to count records with wc(1) or to grep(1) the output.
-r, -resolve
use the system’s name resolver to print DNS names instead of host addresses.
Ip – Command Syntax
OBJECT
link
– network device.
address
– protocol (IP or IPv6) address on a device.
addrlabel
– label configuration for protocol address selection.
neighbour
– ARP or NDISC cache entry.
route
– routing table entry.
rule
– rule in routing policy database.
maddress
– multicast address.
mroute
– multicast routing cache entry.
tunnel
– tunnel over IP.
xfrm
– framework for IPsec protocol.
The names of all objects may be written in full or abbreviated form, f.e. address is abbreviated as addr or just a.
COMMAND
Specifies the action to perform on the object. The set of possible actions depends on the object type. As a rule, it is possible to add, delete and show (or list ) objects, but some objects do not allow all of these operations or have some additional commands. The help command is available for all objects. It prints out a list of available commands and argument syntax conventions.
If no command is given, some default command is assumed. Usually it is list or, if the objects of this class cannot be listed, help.
ip link – network device configuration
link is a network device and the corresponding commands display and change the state of devices.
ip link set – change device attributes
dev NAME (default)
NAME specifies network device to operate on. When configuring SR-IOV Virtual Fuction (VF) devices, this keyword should specify the associated Physical Function (PF) device.
up and down
change the state of the device to UP or DOWN.
arp on or arp off
change the NOARP flag on the device.
multicast on or multicast off
change the MULTICAST flag on the device.
dynamic on or dynamic off
change the DYNAMIC flag on the device.
name NAME
change the name of the device. This operation is not recommended if the device is running or has some addresses already configured.
txqueuelen NUMBER
txqlen NUMBER
change the transmit queue length of the device.
mtu NUMBER
change the MTU of the device.
address LLADDRESS
change the station address of the interface.
broadcast LLADDRESS
brd LLADDRESS
peer LLADDRESS
change the link layer broadcast address or the peer address when the interface is POINTOPOINT.
netns PID
move the device to the network namespace associated with the process PID.
alias NAME
give the device a symbolic name for easy reference.
vf NUM
specify a Virtual Function device to be configured. The associated PF device must be specified using the dev parameter.
mac LLADDRESS – change the station address for the specified VF. The vf parameter must be specified.
vlan VLANID – change the assigned VLAN for the specified VF. When specified, all traffic sent from the VF will be tagged with the specified VLAN ID. Incoming traffic will be filtered for the specified VLAN ID, and will have all VLAN tags stripped before being passed to the VF. Setting this parameter to 0 disables VLAN tagging and filtering. The vf parameter must be specified.
qos VLAN-QOS – assign VLAN QOS (priority) bits for the VLAN tag. When specified, all VLAN tags transmitted by the VF will include the specified priority bits in the VLAN tag. If not specified, the value is assumed to be 0. Both the vf and vlan parameters must be specified. Setting both vlan and qos as 0 disables VLAN tagging and filtering for the VF.
rate TXRATE – change the allowed transmit bandwidth, in Mbps, for the specified VF. Setting this parameter to 0 disables rate limiting. The vf parameter must be specified.
Warning: If multiple parameter changes are requested, ip aborts immediately after any of the changes have failed. This is the only case when ip can move the system to an unpredictable state. The solution is to avoid changing several parameters with one ip link set call.
ip link show – display device attributes
dev NAME (default)
NAME specifies the network device to show. If this argument is omitted all devices are listed.
up
only display running interfaces.
ip address – protocol address management.
The address is a protocol (IP or IPv6) address attached to a network device. Each device must have at least one address to use the corresponding protocol. It is possible to have several different addresses attached to one device. These addresses are not discriminated, so that the term alias is not quite appropriate for them and we do not use it in this document.
The ip addr command displays addresses and their properties, adds new addresses and deletes old ones.
ip address add – add new protocol address.
dev NAME
the name of the device to add the address to.
local ADDRESS (default)
the address of the interface. The format of the address depends on the protocol. It is a dotted quad for IP and a sequence of hexadecimal halfwords separated by colons for IPv6. The ADDRESS may be followed by a slash and a decimal number which encodes the network prefix length.
peer ADDRESS
the address of the remote endpoint for pointopoint interfaces. Again, the ADDRESS may be followed by a slash and a decimal number, encoding the network prefix length. If a peer address is specified, the local address cannot have a prefix length. The network prefix is associated with the peer rather than with the local address.
broadcast ADDRESS
the broadcast address on the interface.
It is possible to use the special symbols ‘+’ and ‘-‘ instead of the broadcast address. In this case, the broadcast address is derived by setting/resetting the host bits of the interface prefix.
label NAME
Each address may be tagged with a label string. In order to preserve compatibility with Linux-2.0 net aliases, this string must coincide with the name of the device or must be prefixed with the device name followed by colon.
scope SCOPE_VALUE
the scope of the area where this address is valid. The available scopes are listed in file /etc/iproute2/rt_scopes. Predefined scope values are:
global – the address is globally valid.
site – (IPv6 only) the address is site local, i.e. it is valid inside this site.
link – the address is link local, i.e. it is valid only on this device.
host – the address is valid only inside this host.
ip address delete – delete protocol address
Arguments: coincide with the arguments of ip addr add. The device name is a required argument. The rest are optional. If no arguments are given, the first address is deleted.
ip address show – look at protocol addresses
dev NAME (default)
name of device.
scope SCOPE_VAL
only list addresses with this scope.
to PREFIX
only list addresses matching this prefix.
label PATTERN
only list addresses with labels matching the PATTERN. PATTERN is a usual shell style pattern.
dynamic and permanent
(IPv6 only) only list addresses installed due to stateless address configuration or only list permanent (not dynamic) addresses.
tentative
(IPv6 only) only list addresses which did not pass duplicate address detection.
deprecated
(IPv6 only) only list deprecated addresses.
primary and secondary
only list primary (or secondary) addresses.
ip address flush – flush protocol addresses
This command flushes the protocol addresses selected by some criteria.
This command has the same arguments as show. The difference is that it does not run when no arguments are given.
Warning: This command (and other flush commands described below) is pretty dangerous. If you make a mistake, it will not forgive it, but will cruelly purge all the addresses.
With the -statistics option, the command becomes verbose. It prints out the number of deleted addresses and the number of rounds made to flush the address list. If this option is given twice, ip addr flush also dumps all the deleted addresses in the format described in the previous subsection.
ip addrlabel – protocol address label management.
IPv6 address label is used for address selection described in RFC 3484. Precedence is managed by userspace, and only label is stored in kernel.
ip addrlabel add – add an address label
the command adds an address label entry to the kernel.
prefix PREFIX
dev DEV
the outgoing interface.
label NUMBER
the label for the prefix. 0xffffffff is reserved.
ip addrlabel del – delete an address label
the command deletes an address label entry in the kernel. Arguments: coincide with the arguments of ip addrlabel add but label is not required.
ip addrlabel list – list address labels
the command show contents of address labels.
ip addrlabel flush – flush address labels
the command flushes the contents of address labels and it does not restore default settings.
ip neighbour – neighbour/arp tables management.
neighbour objects establish bindings between protocol addresses and link layer addresses for hosts sharing the same link. Neighbour entries are organized into tables. The IPv4 neighbour table is known by another name – the ARP table.
The corresponding commands display neighbour bindings and their properties, add new neighbour entries and delete old ones.
ip neighbour add – add a new neighbour entry
ip neighbour change – change an existing entry
ip neighbour replace – add a new entry or change an existing one
These commands create new neighbour records or update existing ones.
to ADDRESS (default)
the protocol address of the neighbour. It is either an IPv4 or IPv6 address.
dev NAME
the interface to which this neighbour is attached.
lladdr LLADDRESS
the link layer address of the neighbour. LLADDRESS can also be null.
nud NUD_STATE
the state of the neighbour entry. nud is an abbreviation for ‘Neigh bour Unreachability Detection’. The state can take one of the following values:
permanent – the neighbour entry is valid forever and can be only be removed administratively.
noarp – the neighbour entry is valid. No attempts to validate this entry will be made but it can be removed when its lifetime expires.
reachable – the neighbour entry is valid until the reachability timeout expires.
stale – the neighbour entry is valid but suspicious. This option to ip neigh does not change the neighbour state if it was valid and the address is not changed by this command.
ip neighbour delete – delete a neighbour entry
This command invalidates a neighbour entry.
The arguments are the same as with ip neigh add, except that lladdr and nud are ignored.
Warning: Attempts to delete or manually change a noarp entry created by the kernel may result in unpredictable behaviour. Particularly, the kernel may try to resolve this address even on a NOARP interface or if the address is multicast or broadcast.
ip neighbour show – list neighbour entries
This commands displays neighbour tables.
to ADDRESS (default)
the prefix selecting the neighbours to list.
dev NAME
only list the neighbours attached to this device.
unused
only list neighbours which are not currently in use.
nud NUD_STATE
only list neighbour entries in this state. NUD_STATE takes values listed below or the special value all which means all states. This option may occur more than once. If this option is absent, ip lists all entries except for none and noarp.
ip neighbour flush – flush neighbour entries
This command flushes neighbour tables, selecting entries to flush by some criteria.
This command has the same arguments as show. The differences are that it does not run when no arguments are given, and that the default neighbour states to be flushed do not include permanent and noarp.
With the -statistics option, the command becomes verbose. It prints out the number of deleted neighbours and the number of rounds made to flush the neighbour table. If the option is given twice, ip neigh flush also dumps all the deleted neighbours.
ip route – routing table management
Manipulate route entries in the kernel routing tables keep information about paths to other networked nodes.
Route types:
unicast – the route entry describes real paths to the destinations covered by the route prefix.
unreachable – these destinations are unreachable. Packets are discarded and the ICMP message host unreachable is generated. The local senders get an EHOSTUNREACH error.
blackhole – these destinations are unreachable. Packets are discarded silently. The local senders get an EINVAL error.
prohibit – these destinations are unreachable. Packets are discarded and the ICMP message communication administratively prohibited is generated. The local senders get an EACCES error.
local – the destinations are assigned to this host. The packets are looped back and delivered locally.
broadcast – the destinations are broadcast addresses. The packets are sent as link broadcasts.
throw – a special control route used together with policy rules. If such a route is selected, lookup in this table is terminated pretending that no route was found. Without policy routing it is equivalent to the absence of the route in the routing table. The packets are dropped and the ICMP message net unreachable is generated. The local senders get an ENETUNREACH error.
nat – a special NAT route. Destinations covered by the prefix are considered to be dummy (or external) addresses which require translation to real (or internal) ones before forwarding. The addresses to translate to are selected with the attribute Warning: Route NAT is no longer supported in Linux 2.6.
via.
anycast – not implemented the destinations are anycast addresses assigned to this host. They are mainly equivalent to local with one difference: such addresses are invalid when used as the source address of any packet.
multicast – a special type used for multicast routing. It is not present in normal routing tables.
Route tables: Linux-2.x can pack routes into several routing tables identified by a number in the range from 1 to 255 or by name from the file /etc/iproute2/rt_tables By default all normal routes are inserted into the main table (ID 254) and the kernel only uses this table when calculating routes.
Actually, one other table always exists, which is invisible but even more important. It is the local table (ID 255). This table consists of routes for local and broadcast addresses. The kernel maintains this table automatically and the administrator usually need not modify it or even look at it.
The multiple routing tables enter the game when policy routing is used.
ip route add – add new route
ip route change – change route
ip route replace – change or add new one
to TYPE PREFIX (default)
the destination prefix of the route. If TYPE is omitted, ip assumes type unicast. Other values of TYPE are listed above. PREFIX is an IP or IPv6 address optionally followed by a slash and the prefix length. If the length of the prefix is missing, ip assumes a full-length host route. There is also a special PREFIX default – which is equivalent to IP 0/0 or to IPv6 ::/0.
tos TOS
dsfield TOS
the Type Of Service (TOS) key. This key has no associated mask and the longest match is understood as: First, compare the TOS of the route and of the packet. If they are not equal, then the packet may still match a route with a zero TOS. TOS is either an 8 bit hexadecimal number or an identifier from /etc/iproute2/rt_dsfield.
metric NUMBER
preference NUMBER
the preference value of the route. NUMBER is an arbitrary 32bit number.
table TABLEID
the table to add this route to. TABLEID may be a number or a string from the file /etc/iproute2/rt_tables. If this parameter is omitted, ip assumes the main table, with the exception of local , broadcast and nat routes, which are put into the local table by default.
dev NAME
the output device name.
via ADDRESS
the address of the nexthop router. Actually, the sense of this field depends on the route type. For normal unicast routes it is either the true next hop router or, if it is a direct route installed in BSD compatibility mode, it can be a local address of the interface. For NAT routes it is the first address of the block of translated IP destinations.
src ADDRESS
the source address to prefer when sending to the destinations covered by the route prefix.
realm REALMID
the realm to which this route is assigned. REALMID may be a number or a string from the file /etc/iproute2/rt_realms.
mtu MTU
mtu lock MTU
the MTU along the path to the destination. If the modifier lock is not used, the MTU may be updated by the kernel due to Path MTU Discovery. If the modifier lock is used, no path MTU discovery will be tried, all packets will be sent without the DF bit in IPv4 case or fragmented to MTU for IPv6.
window NUMBER
the maximal window for TCP to advertise to these destinations, measured in bytes. It limits maximal data bursts that our TCP peers are allowed to send to us.
rtt TIME
the initial RTT (‘Round Trip Time’) estimate. If no suffix is specified the units are raw values passed directly to the routing code to maintain compatability with previous releases. Otherwise if a suffix of s, sec or secs is used to specify seconds; ms, msec or msecs to specify milliseconds; us, usec or usecs to specify microseconds; ns, nsec or nsecs to specify nanoseconds; j, hz or jiffies to specify jiffies, the value is converted to what the routing code expects.
rttvar TIME (2.3.15+ only)
the initial RTT variance estimate. Values are specified as with rtt above.
rto_min TIME (2.6.23+ only)
the minimum TCP Retransmission TimeOut to use when communicating with this destination. Values are specified as with rtt above.
ssthresh NUMBER (2.3.15+ only)
an estimate for the initial slow start threshold.
cwnd NUMBER (2.3.15+ only)
the clamp for congestion window. It is ignored if the lock flag is not used.
initcwnd NUMBER
the maximum initial congestion window (cwnd) size in MSS of a TCP connection.
initrwnd NUMBER (2.6.33+ only)
the initial receive window size for connections to this destination. Actual window size is this value multiplied by the MSS of the connection. The default value is zero, meaning to use Slow Start value.
advmss NUMBER (2.3.15+ only)
the MSS (‘Maximal Segment Size’) to advertise to these destinations when establishing TCP connections. If it is not given, Linux uses a default value calculated from the first hop device MTU. (If the path to these destination is asymmetric, this guess may be wrong.)
reordering NUMBER (2.3.15+ only)
Maximal reordering on the path to this destination. If it is not given, Linux uses the value selected with sysctl variable net/ipv4/tcp_reordering.
nexthop NEXTHOP
the nexthop of a multipath route. NEXTHOP is a complex value with its own syntax similar to the top level argument lists:
via ADDRESS – is the nexthop router.
dev NAME – is the output device.
weight NUMBER – is a weight for this element of a multipath route reflecting its relative bandwidth or quality.
scope SCOPE_VAL
the scope of the destinations covered by the route prefix. SCOPE_VAL may be a number or a string from the file /etc/iproute2/rt_scopes. If this parameter is omitted, ip assumes scope global for all gatewayed unicast routes, scope link for direct unicast and broadcast routes and scope host for local routes.
protocol RTPROTO
the routing protocol identifier of this route. RTPROTO may be a number or a string from the file /etc/iproute2/rt_protos. If the routing protocol ID is not given, ip assumes protocol boot (i.e. it assumes the route was added by someone who doesn’t understand what they are doing). Several protocol values have a fixed interpretation. Namely:
redirect – the route was installed due to an ICMP redirect.
kernel – the route was installed by the kernel during autoconfiguration.
boot – the route was installed during the bootup sequence. If a routing daemon starts, it will purge all of them.
static – the route was installed by the administrator to override dynamic routing. Routing daemon will respect them and, probably, even advertise them to its peers.
ra – the route was installed by Router Discovery protocol.
The rest of the values are not reserved and the administrator is free to assign (or not to assign) protocol tags.
onlink
pretend that the nexthop is directly attached to this link, even if it does not match any interface prefix.
equalize
allow packet by packet randomization on multipath routes. Without this modifier, the route will be frozen to one selected nexthop, so that load splitting will only occur on per-flow base. equalize only works if the kernel is patched.
ip route delete – delete route
ip route del has the same arguments as ip route add, but their semantics are a bit different.
Key values (to, tos, preference and table) select the route to delete. If optional attributes are present, ip verifies that they coincide with the attributes of the route to delete. If no route with the given key and attributes was found, ip route del fails.
ip route show – list routes
the command displays the contents of the routing tables or the route(s) selected by some criteria.
to SELECTOR (default)
only select routes from the given range of destinations. SELECTOR consists of an optional modifier (root, match or exact) and a prefix. root PREFIX selects routes with prefixes not shorter than PREFIX. F.e. root 0/0 selects the entire routing table. match PREFIX selects routes with prefixes not longer than PREFIX. F.e. match 10.0/16 selects 10.0/16, 10/8 and 0/0, but it does not select 10.1/16 and 10.0.0/24. And exact PREFIX (or just PREFIX) selects routes with this exact prefix. If neither of these options are present, ip assumes root 0/0 i.e. it lists the entire table.
tos TOS
dsfield TOS only select routes with the given TOS.
table TABLEID
show the routes from this table(s). The default setting is to show tablemain. TABLEID may either be the ID of a real table or one of the special values:
all – list all of the tables.
cache – dump the routing cache.
cloned
cached
list cloned routes i.e. routes which were dynamically forked from other routes because some route attribute (f.e. MTU) was updated. Actually, it is equivalent to table cache.
from SELECTOR
the same syntax as for to, but it binds the source address range rather than destinations. Note that the from option only works with cloned routes.
protocol RTPROTO
only list routes of this protocol.
scope SCOPE_VAL
only list routes with this scope.
type TYPE
only list routes of this type.
dev NAME
only list routes going via this device.
via PREFIX
only list routes going via the nexthop routers selected by PREFIX.
src PREFIX
only list routes with preferred source addresses selected by PREFIX.
realm REALMID
realms FROMREALM/TOREALM
only list routes with these realms.
ip route flush – flush routing tables
this command flushes routes selected by some criteria.
The arguments have the same syntax and semantics as the arguments of ip route show, but routing tables are not listed but purged. The only difference is the default action: show dumps all the IP main routing table but flush prints the helper page.
With the -statistics option, the command becomes verbose. It prints out the number of deleted routes and the number of rounds made to flush the routing table. If the option is given twice, ip route flush also dumps all the deleted routes in the format described in the previous subsection.
ip route get – get a single route
this command gets a single route to a destination and prints its contents exactly as the kernel sees it.
to ADDRESS (default)
the destination address.
from ADDRESS
the source address.
tos TOS
dsfield TOS
the Type Of Service.
iif NAME
the device from which this packet is expected to arrive.
oif NAME
force the output device on which this packet will be routed.
connected
if no source address (option from) was given, relookup the route with the source set to the preferred address received from the first lookup. If policy routing is used, it may be a different route.
Note that this operation is not equivalent to ip route show. show shows existing routes. get resolves them and creates new clones if necessary. Essentially, get is equivalent to sending a packet along this path. If the iif argument is not given, the kernel creates a route to output packets towards the requested destination. This is equivalent to pinging the destination with a subsequent ip route ls cache, however, no packets are actually sent. With the iif argument, the kernel pretends that a packet arrived from this interface and searches for a path to forward the packet.
ip rule – routing policy database management
Rules in the routing policy database control the route selection algorithm.
Classic routing algorithms used in the Internet make routing decisions based only on the destination address of packets (and in theory, but not in practice, on the TOS field).
In some circumstances we want to route packets differently depending not only on destination addresses, but also on other packet fields: source address, IP protocol, transport protocol ports or even packet payload. This task is called ‘policy routing’.
To solve this task, the conventional destination based routing table, ordered according to the longest match rule, is replaced with a ‘routing policy database’ (or RPDB), which selects routes by executing some set of rules.
Each policy routing rule consists of a selector and an action predicate. The RPDB is scanned in the order of increasing priority. The selector of each rule is applied to {source address, destination address, incoming interface, tos, fwmark} and, if the selector matches the packet, the action is performed. The action predicate may return with success. In this case, it will either give a route or failure indication and the RPDB lookup is terminated. Otherwise, the RPDB program continues on the next rule.
Semantically, natural action is to select the nexthop and the output device.
At startup time the kernel configures the default RPDB consisting of three rules:
1.
Priority: 0, Selector: match anything, Action: lookup routing table local (ID 255). The local table is a special routing table containing high priority control routes for local and broadcast addresses.
Rule 0 is special. It cannot be deleted or overridden.
2.
Priority: 32766, Selector: match anything, Action: lookup routing table main (ID 254). The main table is the normal routing table containing all non-policy routes. This rule may be deleted and/or overridden with other ones by the administrator.
3.
Priority: 32767, Selector: match anything, Action: lookup routing table default (ID 253). The default table is empty. It is reserved for some post-processing if no previous default rules selected the packet. This rule may also be deleted.
Each RPDB entry has additional attributes. F.e. each rule has a pointer to some routing table. NAT and masquerading rules have an attribute to select new IP address to translate/masquerade. Besides that, rules have some optional attributes, which routes have, namely realms. These values do not override those contained in the routing tables. They are only used if the route did not select any attributes.
The RPDB may contain rules of the following types:
unicast – the rule prescribes to return the route found in the routing table referenced by the rule.
blackhole – the rule prescribes to silently drop the packet.
unreachable – the rule prescribes to generate a ‘Network is unreachable’ error.
prohibit – the rule prescribes to generate ‘Communication is administratively prohibited’ error.
nat – the rule prescribes to translate the source address of the IP packet into some other value.
ip rule add – insert a new rule
ip rule delete – delete a rule
type TYPE (default)
the type of this rule. The list of valid types was given in the previous subsection.
from PREFIX
select the source prefix to match.
to PREFIX
select the destination prefix to match.
iif NAME
select the incoming device to match. If the interface is loopback, the rule only matches packets originating from this host. This means that you may create separate routing tables for forwarded and local packets and, hence, completely segregate them.
tos TOS
dsfield TOS
select the TOS value to match.
fwmark MARK
select the fwmark value to match.
priority PREFERENCE
the priority of this rule. Each rule should have an explicitly set unique priority value. The options preference and order are synonyms with priority.
table TABLEID
the routing table identifier to lookup if the rule selector matches. It is also possible to use lookup instead of table.
realms FROM/TO
Realms to select if the rule matched and the routing table lookup succeeded. Realm TO is only used if the route did not select any realm.
nat ADDRESS
The base of the IP address block to translate (for source addresses). The ADDRESS may be either the start of the block of NAT addresses (selected by NAT routes) or a local host address (or even zero). In the last case the router does not translate the packets, but masquerades them to this address. Using map-to instead of nat means the same thing.
Warning: Changes to the RPDB made with these commands do not become active immediately. It is assumed that after a script finishes a batch of updates, it flushes the routing cache with ip route flush cache.
ip rule flush – also dumps all the deleted rules.
This command has no arguments.
ip rule show – list rules
This command has no arguments. The options list or lst are synonyms with show.
ip maddress – multicast addresses management
maddress objects are multicast addresses.
ip maddress show – list multicast addresses
dev NAME (default)
the device name.
ip maddress add – add a multicast address
ip maddress delete – delete a multicast address
these commands attach/detach a static link layer multicast address to listen on the interface. Note that it is impossible to join protocol multicast groups statically. This command only manages link layer addresses.
address LLADDRESS (default)
the link layer multicast address.
dev NAME
the device to join/leave this multicast address.
ip mroute – multicast routing cache management
mroute objects are multicast routing cache entries created by a user level mrouting daemon (f.e. pimd or mrouted ).
Due to the limitations of the current interface to the multicast routing engine, it is impossible to change mroute objects administratively, so we may only display them. This limitation will be removed in the future.
ip mroute show – list mroute cache entries
to PREFIX (default)
the prefix selecting the destination multicast addresses to list.
iif NAME
the interface on which multicast packets are received.
from PREFIX
the prefix selecting the IP source addresses of the multicast route.
ip tunnel – tunnel configuration
tunnel objects are tunnels, encapsulating packets in IP packets and then sending them over the IP infrastructure. The encapulating (or outer) address family is specified by the -f option. The default is IPv4.
ip tunnel add – add a new tunnel
ip tunnel change – change an existing tunnel
ip tunnel delete – destroy a tunnel
name NAME (default)
select the tunnel device name.
mode MODE
set the tunnel mode. Available modes depend on the encapsulating address family.
Modes for IPv4 encapsulation available: ipip, sit, isatap and gre.
Modes for IPv6 encapsulation available: ip6ip6, ipip6 and any.
remote ADDRESS
set the remote endpoint of the tunnel.
local ADDRESS
set the fixed local address for tunneled packets. It must be an address on another interface of this host.
ttl N
set a fixed TTL N on tunneled packets. N is a number in the range 1–255. 0 is a special value meaning that packets inherit the TTL value. The default value for IPv4 tunnels is: inherit. The default value for IPv6 tunnels is: 64.
tos T
dsfield T
tclass T
set a fixed TOS (or traffic class in IPv6) T on tunneled packets. The default value is: inherit.
dev NAME
bind the tunnel to the device NAME so that tunneled packets will only be routed via this device and will not be able to escape to another device when the route to endpoint changes.
nopmtudisc
disable Path MTU Discovery on this tunnel. It is enabled by default. Note that a fixed ttl is incompatible with this option: tunnelling with a fixed ttl always makes pmtu discovery.
key K
ikey K
okey K
( only GRE tunnels ) use keyed GRE with key K. K is either a number or an IP address-like dotted quad. The key parameter sets the key to use in both directions. The ikey and okey parameters set different keys for input and output.
csum, icsum, ocsum
( only GRE tunnels ) generate/require checksums for tunneled packets. The ocsum flag calculates checksums for outgoing packets. The icsum flag requires that all input packets have the correct checksum. The csum flag is equivalent to the combination icsum ocsum.
seq, iseq, oseq
( only GRE tunnels ) serialize packets. The oseq flag enables sequencing of outgoing packets. The iseq flag requires that all input packets are serialized. The seq flag is equivalent to the combination iseq oseq. It isn’t work. Don’t use it.
dscp inherit
( only IPv6 tunnels ) Inherit DS field between inner and outer header.
encaplim ELIM
( only IPv6 tunnels ) set a fixed encapsulation limit. Default is 4.
flowlabel FLOWLABEL
( only IPv6 tunnels ) set a fixed flowlabel.
ip tunnel prl – potential router list (ISATAP only)
dev NAME
mandatory device name.
prl-default ADDR
prl-nodefault ADDR
prl-delete ADDR
Add or delete ADDR as a potential router or default router.
ip tunnel show – list tunnels
This command has no arguments.
ip monitor and rtmon – state monitoring
The ip utility can monitor the state of devices, addresses and routes continuously. This option has a slightly different format. Namely, the monitor command is the first in the command line and then the object list follows:
ip monitor [ all | LISTofOBJECTS ]
OBJECT-LIST is the list of object types that we want to monitor. It may contain link, address and route. If no file argument is given, ip opens RTNETLINK, listens on it and dumps state changes in the format described in previous sections.
If a file name is given, it does not listen on RTNETLINK, but opens the file containing RTNETLINK messages saved in binary format and dumps them. Such a history file can be generated with the rtmon utility. This utility has a command line syntax similar to ip monitor. Ideally, rtmon should be started before the first network configuration command is issued. F.e. if you insert:
rtmon file /var/log/rtmon.log
in a startup script, you will be able to view the full history later.
Certainly, it is possible to start rtmon at any time. It prepends the history with the state snapshot dumped at the moment of starting.
ip xfrm – setting xfrm
xfrm is an IP framework, which can transform format of the datagrams,
i.e. encrypt the packets with some algorithm. xfrm policy and xfrm state are associated through templates TMPL_LIST. This framework is used as a part of IPsec protocol.
ip xfrm state add – add new state into xfrm
ip xfrm state update – update existing xfrm state
ip xfrm state allocspi – allocate SPI value
MODE
is set as default to transport, but it could be set to tunnel,ro or beet.
FLAG-LIST
contains one or more flags.
FLAG
could be set to noecn, decap-dscp or wildrecv.
ENCAP
encapsulation is set to encapsulation type ENCAP-TYPE, source port SPORT, destination port DPORT and OADDR.
ENCAP-TYPE
could be set to espinudp or espinudp-nonike.
ALGO-LIST
contains one or more algorithms ALGO which depend on the type of algorithm set by ALGO_TYPE. It can be used these algoritms enc, auth or comp.
ip xfrm policy add – add a new policy
ip xfrm policy update – update an existing policy
ip xfrm policy delete – delete existing policy
ip xfrm policy get – get existing policy
ip xfrm policy deleteall – delete all existing xfrm policy
ip xfrm policy list – print out the list of xfrm policy
ip xfrm policy flush – flush policies
It can be flush all policies or only those specified with ptype.
dir DIR
directory could be one of these: inp, out or fwd.
SELECTOR
selects for which addresses will be set up the policy. The selector is defined by source and destination address.
UPSPEC
is defined by source port sport, destination port dport, type as number and code also number.
dev DEV
specify network device.
index INDEX
the number of indexed policy.
ptype PTYPE
type is set as default on main, could be switch on sub.
action ACTION
is set as default on allow. It could be switch on block.
priority PRIORITY
priority is a number. Default priority is set on zero.
LIMIT-LIST
limits are set in seconds, bytes or numbers of packets.
TMPL-LIST
template list is based on ID, mode, reqid and level.
ID
is specified by source address, destination address, proto and value of spi.
XFRM_PROTO
values: esp, ah, comp, route2 or hao.
MODE
is set as default on transport, but it could be set on tunnel or beet.
LEVEL
is set as default on required and the other choice is use.
UPSPEC
is specified by sport, dport, type and code (NUMBER).
ip xfrm monitor – is used for listing all objects or defined group of them.
The xfrm monitor can monitor the policies for all objects or defined group of them
ifconfig or ip
The command /bin/ip has been around for some time now. But people continue using the older command /sbin/ifconfig. Let’s be clear: ifconfig will not quickly go away, but its newer version, ip, is more powerful and will eventually replace it.
The man page of ip may look intimidating at first, but once you get familiar with the command syntax, it is an easy read. This page will not introduce the new features ofip. It rather features a side-by-side comparison if ifconfig and ip to get a quick overview of the command syntax.
Show network devices and configuration ¶
ifconfig
ip addr show ip link show
Enable a network interface ¶
ifconfig eth0 up
ip link set eth0 up
A network interface is disabled in a similar way:
ifconfig eth0 down
ip link set eth0 down
Set IP address ¶
ifconfig eth0 192.168.0.77
ip address add 192.168.0.77 dev eth0
This was the simple version of the command. Often, also the network mask or the broadcast address need to be specified. The following examples show the ifconfigand ip variants.
Needless to say that the netmask can also be given in CIDR notation, e.g. as 192.168.0.77/24.
ifconfig eth0 192.168.0.77 netmask 255.255.255.0 broadcast 192.168.0.255
ip addr add 192.168.0.77/24 broadcast 192.168.0.255 dev eth0
Delete an IP address ¶
With ip it is also possible to delete an address:
ip addr del 192.168.0.77/24 dev eth0
Add alias interface ¶
ifconfig eth0:1 10.0.0.1/8
ip addr add 10.0.0.1/8 dev eth0 label eth0:1
ARP protocol ¶
Add an entry in your ARP table.
arp -i eth0 -s 192.168.0.1 00:11:22:33:44:55
ip neigh add 192.168.0.1 lladdr 00:11:22:33:44:55 nud permanent dev eth0
Switch ARP resolution off on one device
ifconfig -arp eth0
ip link set dev eth0 arp off
netstat – Linux man page
netstat – Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. Its really good stuff!
netstat [address_family_options] [–tcp|-t] [–udp|-u] [–raw|-w] [–listening|-l] [–all|-a] [–numeric|-n] [–numeric-hosts][–numeric-ports][–numeric-ports] [–symbolic|-N] [–extend|-e[–extend|-e]] [–timers|-o] [–program|-p] [–verbose|-v] [–continuous|-c][delay]
netstat {–route|-r} [address_family_options] [–extend|-e[–extend|-e]] [–verbose|-v] [–numeric|-n] [–numeric-hosts][–numeric-ports][–numeric-ports] [–continuous|-c][delay]
netstat {–interfaces|-I|-i} [iface] [–all|-a] [–extend|-e] [–verbose|-v] [–program|-p] [–numeric|-n] [–numeric-hosts][–numeric-ports][–numeric-ports] [–continuous|-c][delay]
netstat {–groups|-g} [–numeric|-n] [–numeric-hosts][–numeric-ports][–numeric-ports] [–continuous|-c] [delay]
netstat {–masquerade|-M} [–extend|-e] [–numeric|-n] [–numeric-hosts][–numeric-ports][–numeric-ports] [–continuous|-c] [delay]
netstat {–statistics|-s} [–tcp|-t] [–udp|-u] [–raw|-w] [delay]
netstat {–version|-V}
netstat {–help|-h}
address_family_options:
[–protocol={inet,unix,ipx,ax25,netrom,ddp}[,…]] [–unix|-x] [–inet|–ip] [–ax25] [–ipx] [–netrom] [–ddp]
Note
This program is obsolete. Replacement for netstat is ss. Replacement for netstat -r is ip route. Replacement for netstat -i is ip -s link. Replacement for netstat -g is ip maddr.
Description
Netstat prints information about the Linux networking subsystem. The type of information printed is controlled by the first argument, as follows:
(none)
By default, netstat displays a list of open sockets. If you don’t specify any address families, then the active sockets of all configured address families will be printed.
–route , -r
Display the kernel routing tables.
–groups , -g
Display multicast group membership information for IPv4 and IPv6.
–interfaces=iface , -I=iface , -i
Display a table of all network interfaces, or the specified iface.
–masquerade , -M
Display a list of masqueraded connections.
–statistics , -s
Display summary statistics for each protocol.
Options
–verbose , -v
Tell the user what is going on by being verbose. Especially print some useful information about unconfigured address families.
–numeric , -n
Show numerical addresses instead of trying to determine symbolic host, port or user names.
–numeric-hosts
shows numerical host addresses but does not affect the resolution of port or user names.
–numeric-ports
shows numerical port numbers but does not affect the resolution of host or user names.
–numeric-users
shows numerical user IDs but does not affect the resolution of host or port names.
–protocol=family , -A
Specifies the address families (perhaps better described as low level protocols) for which connections are to be shown. family is a comma (‘,’) separated list of address family keywords like inet, unix, ipx, ax25, netrom, and ddp. This has the same effect as using the –inet, –unix (-x), –ipx, –ax25, –netrom, and –ddp options.
The address family inet includes raw, udp and tcp protocol sockets.
-c, –continuous
This will cause netstat to print the selected information every second continuously.
-e, –extend
Display additional information. Use this option twice for maximum detail.
-o, –timers
Include information related to networking timers.
-p, –program
Show the PID and name of the program to which each socket belongs.
-l, –listening
Show only listening sockets. (These are omitted by default.)
-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
-f
Print routing information from the FIB. (This is the default.)
-c
Print routing information from the route cache.
-Z –context
If SELinux enabled print SELinux context.
-T –notrim
Stop trimming long addresses.
delay
Netstat will cycle printing through statistics every delay seconds. UP.
Output
Active Internet connections (TCP, UDP, raw)
Proto
The protocol (tcp, udp, raw) used by the socket.
Recv-Q
The count of bytes not copied by the user program connected to this socket.
Send-Q
The count of bytes not acknowledged by the remote host.
Local Address
Address and port number of the local end of the socket. Unless the –numeric (-n) option is specified, the socket address is resolved to its canonical host name (FQDN), and the port number is translated into the corresponding service name.
Foreign Address
Address and port number of the remote end of the socket. Analogous to “Local Address.”
State
The state of the socket. Since there are no states in raw mode and usually no states used in UDP, this column may be left blank. Normally this can be one of several values:
- ESTABLISHED
- The socket has an established connection.
- SYN_SENT
- The socket is actively attempting to establish a connection.
- SYN_RECV
- A connection request has been received from the network.
- FIN_WAIT1
- The socket is closed, and the connection is shutting down.
- FIN_WAIT2
- Connection is closed, and the socket is waiting for a shutdown from the remote end.
- TIME_WAIT
- The socket is waiting after close to handle packets still in the network.
- CLOSED
- The socket is not being used.
- CLOSE_WAIT
- The remote end has shut down, waiting for the socket to close.
- LAST_ACK
- The remote end has shut down, and the socket is closed. Waiting for acknowledgement.
- LISTEN
- The socket is listening for incoming connections. Such sockets are not included in the output unless you specify the –listening (-l) or –all (-a) option.
- CLOSING
- Both sockets are shut down but we still don’t have all our data sent.
- UNKNOWN
- The state of the socket is unknown.
User
The username or the user id (UID) of the owner of the socket.
PID/Program name
Slash-separated pair of the process id (PID) and process name of the process that owns the socket. –program causes this column to be included. You will also need superuserprivileges to see this information on sockets you don’t own. This identification information is not yet available for IPX sockets.
Timer
(this needs to be written)
Active UNIX domain Sockets
Proto
The protocol (usually unix) used by the socket.
RefCnt
The reference count (i.e. attached processes via this socket).
Flags
The flags displayed is SO_ACCEPTON (displayed as ACC), SO_WAITDATA (W) or SO_NOSPACE (N). SO_ACCECPTON is used on unconnected sockets if their corresponding processes are waiting for a connect request. The other flags are not of normal interest.
Type
There are several types of socket access:
- SOCK_DGRAM
- The socket is used in Datagram (connectionless) mode.
- SOCK_STREAM
- This is a stream (connection) socket.
- SOCK_RAW
- The socket is used as a raw socket.
- SOCK_RDM
- This one serves reliably-delivered messages.
- SOCK_SEQPACKET
- This is a sequential packet socket.
- SOCK_PACKET
- Raw interface access socket.
- UNKNOWN
- Who ever knows what the future will bring us – just fill in here 🙂
State
This field will contain one of the following Keywords:
- FREE
- The socket is not allocated
- LISTENING
- The socket is listening for a connection request. Such sockets are only included in the output if you specify the –listening (-l) or –all (-a) option.
- CONNECTING
- The socket is about to establish a connection.
- CONNECTED
- The socket is connected.
- DISCONNECTING
- The socket is disconnecting.
- (empty)
- The socket is not connected to another one.
- UNKNOWN
- This state should never happen.
PID/Program name
Process ID (PID) and process name of the process that has the socket open. More info available in Active Internet connections section written above.
Path
This is the path name as which the corresponding processes attached to the socket.
Active IPX sockets
(this needs to be done by somebody who knows it)
Active NET/ROM sockets
(this needs to be done by somebody who knows it)
Active AX.25 sockets
(this needs to be done by somebody who knows it)
Notes
Starting with Linux release 2.2 netstat -i does not show interface statistics for alias interfaces. To get per alias interface counters you need to setup explicit rules using theipchains(8) command.
Files
/etc/services — The services translation
file
/proc — Mount point for the proc filesystem, which gives access to kernel status information via the following files.
/proc/net/dev — device
information
/proc/net/raw — raw socket information
/proc/net/tcp — TCP
socket information
/proc/net/udp — UDP socket information
/proc/net/igmp — IGMP multicast information
/proc/net/unix — Unix domain socket information
/proc/net/ipx — IPX socket information
/proc/net/ax25 — AX25 socket information
/proc/net/appletalk — DDP (appletalk) socket information
/proc/net/nr — NET/ROM socket information
/proc/net/route — IP routing information
/proc/net/ax25_route — AX25 routing information
/proc/net/ipx_route — IPX routing information
/proc/net/nr_nodes — NET/ROM nodelist
/proc/net/nr_neigh — NET/ROM neighbours
/proc/net/ip_masquerade — masqueraded connections
/proc/net/snmp — statistics
netstat again
Netstat is the most frequent tool used for monitoring network connections on a Linux servers. Netstat returns a variety of information on active connections such as their current status, what hosts are involved, and which programs are involved. You can also see information about the routing table and even get statistics on your network interfaces. Netstat is a good all-around utility and it is an essential tool for the Linux administrators.
If you just type netstat, it would display a long list of information that’s usually more than you want to go through at any given time. The trick is that how to keeping the information useful and what you’re looking for and how to tell netstat to only display that information.
Below is some of the command to find out number of connections to server usingnetstat, grep, cut, awk, uniq, sort.
To find out the number of connections from an IP.
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | uniq -c | sort -n
In the above command AWK print out the 5th column of netstat output, the CUT part cuts every line at the first space character and take the first piece, than we just have to SORT the results and take the UNIQUE values.
To find out the largest number of established connections.
netstat -na | grep ‘ESTABLISHED’ | awk ‘{print $4}’ | cut -d: -f1 | uniq -c | sort -rn
In the above command GREP is been used to find the line containing “ESTABLISHED“, AWK print out the 4th column of netstat output. CUT part cuts every line at the first space character and take the first piece, than we just have to SORT the results and take the UNIQUE values.
To check max number of connections to server.
netstat -nap |grep ‘tcp|udp’ | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n | tail
In the above command GREP is been used to find the line containing “tcp/udp” [ if you want to sort such lines which are matching two or more different pattern then simply define all patterns in single quote and separate them using |] , AWK print out the 5th column of netstat output. CUT part cuts every line at the first space character and take the first piece, than we just have to SORT the results and take the UNIQUE values.TAIL command print the last part (10 lines) of the output.
To find out the largest number of established connections with port number.
netstat -na | grep ‘ESTABLISHED’ | awk ‘{print $4}’ | uniq -c | sort -rn
To find out the number of connections to port 80 [http] from each IP.
netstat -plan|grep :80|awk {‘print $5′}|cut -d: -f 1|sort|uniq -c|sort -n
Similarly, you can find out the number of connections to port 25 from each IP as.
netstat -plan|grep :25|awk {‘print $5′}|cut -d: -f 1|sort|uniq -c|sort -n
NETSTAT is the most useful tool to detect and determine whether a server is under DoS or DDoS attack (Distributed Denial of Service).
Article from
netstat cheat
Whenever a client connects to a server via network, a connection is established and opened on the system. On a busy high load server, the number of connections connected to the server can be run into large amount till hundreds if not thousands. Find out and get a list of connections on the server by each node, client or IP address is useful for system scaling planning, and in most cases, detect and determine whether a web server is under DoS or DDoS attack (Distributed Denial of Service), where an IP sends large amount of connections to the server. To check connection numbers on the server, administrators and webmasters can make use of netstat command.
Below is some of the example a typically use command syntax for ‘netstat’ to check and show the number of connections a server has. Users can also use ‘man netstat’ command to get detailed netstat help and manual where there are lots of configurable options and flags to get meaningful lists and results.
netstat -na
Display all active Internet connections to the servers and only established connections are included.
netstat -an | grep :80 | sort
Show only active Internet connections to the server at port 80 and sort the results. Useful in detecting single flood by allowing users to recognize many connections coming from one IP.
netstat -n -p|grep SYN_REC | wc -l
Let users know how many active SYNC_REC are occurring and happening on the server. The number should be pretty low, preferably less than 5. On DoS attack incident or mail bombed, the number can jump to twins. However, the value always depends on system, so a high value may be average in another server.
netstat -n -p | grep SYN_REC | sort -u
List out the all IP addresses involved instead of just count.
netstat -n -p | grep SYN_REC | awk '{print $5}' | awk -F: '{print $1}'
List all the unique IP addresses of the node that are sending SYN_REC connection status.
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
Use netstat command to calculate and count the number of connections each IP address makes to the server.
netstat -anp |grep 'tcp|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
List count of number of connections the IPs are connected to the server using TCP or UDP protocol.
netstat -ntu | grep ESTAB | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr
Check on ESTABLISHED connections instead of all connections, and displays the connections count for each IP.
netstat -plan|grep :80|awk {'print $5'}|cut -d: -f 1|sort|uniq -c|sort -nk 1
Show and list IP address and its connection count that connect to port 80 on the server. Port 80 is used mainly by HTTP web page request.
Original article from http://www.mydigitallife.info/how-to-find-and-check-number-of-connections-to-a-server/
Hello linux people!
Hello,
I am Vitalijus Ryzakovas and welcome to my new Linux4you.TK website. This website is my notes, I will keep there interesting thing for me.
Visitors are welcome. 😉