Linux Commands Examples

A great documentation place for Linux commands

ip

show / manipulate routing, devices, policy routing and tunnels

Synopsis

ip [ OPTIONS ] OBJECT { COMMAND | help }

OBJECT := { link | addr | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddr | mroute | mrule | monitor | xfrm | netns | l2tp | tcp_metrics }

OPTIONS := { -V[ersion] | -s[tatistics] | -r[esolve] | -f[amily] { inet | inet6 | ipx | dnet | link } | -o[neline] }


add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!

examples

2
source

What does "network" mean in the /etc/network/interfaces file?

For your case, network is 192.168.1.0, which means your ip address is in the network range, 192.168.1.0 to 192.168.1.255

You can always get your network base address easily by doing ip & mask, where & is logical AND.

0
source

ip versus ifconfig

Simple answer: On Linux ifconfig is obsolete.

From man ifconfig:

This program is obsolete! For replacement check ip addr and ip link. For statistics use ip -s link.

0
source

How can I list all IPs in the connected network, through Terminal preferably?

In windows this would be "arp -a" I believe that an equivalent of that in Linux would be "arp -e".

This information can be found from the man page for arp :

arp with no mode specifier will print the current content of the table.
-e : Use default Linux style output format (with fixed columns).
0
source

Three computers accessing internet but only two network interfaces showing in ´ifconfig´, why?

I am not sure if I understand correctly. But you have 1 Wireless gateway and 3 Devices connected to it?

So doing ifconfig only shows PHYSICAL hardware/connections on the PC that ran the command - not the connections available or other device.

ifconfig stands for interface configuration

  • An interface if a virtual or physical layer on the computer that enables it to communicate with other devices using a standard, for example in your case TCP/IP

  • eth0 could be your Wired Network card running at 10/100/1000

  • eth1 is possibly your wirless interface running at a/b/g/n speeds.
  • lo is a virtual interface and is called a loopback and bind to your computer using home (127.0.0.1) or (localhost) or whatever your computers name is(because it loops back to it self)

To see other computers you need to use something like ARP and to find other computers or devices within your network range.

Also as suggested you can use a wireless tool iwconfig to scan for access points (an access point is not an interface- but the access point it self uses an interface to communicates with other devices found in ARP)

And you only have 1 internet connection, not 3.

In total you should have 5 ARP entries - 2 PC's, 1Notebook, 1Switch and 1 Modem

enter image description here

So as you can see in the illustration, each host has an interface of eth0, the gateway has eth0 and the ISP on the other side has eth0. the more interfaces a device has the higher the number.

0
source

How to route only specific subnet (source ip) to a particular interface?

You must use the route command. For example if you want to route all ip of 192.168.1.xxx to a particular device you have to use the following command:

route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0

With that command you say that all the packets sent from that subnet must be sent to the eth0 interface. If you need to add also a gateway for that connection you can use that:

route add -net 192.168.1.0 netmask 255.255.255.0  gw 192.168.1.1
0
source

What is the maximum number of IPs that can be assigned to a given computer?

More than you could ever possibly need. Use ip addr add to add addresses to an interface.

0
source

In Ubuntu, routes are not added as defined in rc.local file....why?

rc.local is not the best place to set up additional NIC aliases and routes.

Just use /etc/network/interfaces for that.

NIC alias example

static routes example

Concerning your problem:

you use an absolute path to the ifconfig tool, but a relative path to the ip tool. Try using an absolute path there too. Find it by using which ip or whereis ip.

0
source

finding IP address using Linux command prompt

If your machine is assigned a local IP address, it may not know your public-facing address. You can query a server not on your local network to discover your public-facing address.

$ curl whatismyip.org
0
source

Check external IP from a Linux headless server

The follwoing will do the trick.

curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
0
source

Use Shorewall to port-forward requests based on the domain requested to different servers

Shorewall (more specifically, iptables) works in the transport layer and is not suitable for making decisions based on application layer HTTP information. What you want is a reverse proxy server. nginx is a good option.

0
source

Resolving hostnames without DHCP

DHCP does not do hostname resolution; it just offers a method for automatic registration on a locally running DNS server.

Your choices are:

  • mDNS (avahi-daemon + nss_mdns) – names are always in the form name.local; used natively in Mac OS X and available for Windows; uses multicast.

  • NBNS (Samba nmbd + nss_wins) – used by Windows and compatible with Mac OS X; uses broadcast packets.

  • Edit /etc/hosts on each computer: 192.168.1.2 computerone

0
source

Same IP for WLAN and ethernet on Linux

I'm not sure keeping the same IP will help but this might just work:

  1. Connect with cable and set your IP address manually.
  2. Pull the cable and set the the same IP address manually and also change the MAC address to your Ethernet MAC.
  3. Disable DHCP on the WiFi router (I assume that you connect to the same router via cable and wireless).

Setting the IP address can be done in the network manager if you're using a typical Gnome setup.

You don't necessarily have to disable DHCP, my router has options to give DHCP addresses e.g. only above 192.168.0.10. So I can set manual addresses 192.168.1.[2-9] and DHCP addresses will start from 192.168.1.10. In such a situation you could try setting both your wired and wireless IP to 192.168.1.5.

0
source

ssh: connect to host port 22: Connection refused with external ip address

Are you sure you did the correct thing on the router (i.e. does this work with another port on an other service already)?

I'm asking because "connection refused" happens on TCP level and the reason usually is that either nobody is listening on that port on the target machine (that would be the equivalent of sshd not running) or some firewall blocking it.

Since you say it works with an address of your local network, it would appear to be the router that's either not doing the forwarding or forwards to something else.

0
source

routing a secondary IP-addr. of a different private network on the same interface

iptables -t nat -A POSTROUTING -o wlan2 -j SNAT -s 172.16.1.62/24 --to-source 192.168.1.63

Seems to do just that:

# telnet -b 172.16.1.62 google.com 80
Trying 173.194.32.33...
Connected to arn06s02-in-f1.1e100.net.
Escape character is '^]'.

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.

-l, -loops

Specify maximum number of loops the ’ip addr flush’ logic will attempt before giving up. The default is 10. Zero (0) means loop until all addresses are removed.

-f, -family

followed by protocol family identifier: inet, inet6,bridge,ipx,dnet 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.

-B

shortcut for -family bridge.

-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
address

- protocol (IP or IPv6) address on a device.

addrlabel

- label configuration for protocol address selection.

l2tp

- tunnel ethernet over IP (L2TPv3).

link

- network device.

maddress

- multicast address.

monitor

- watch for netlink messages.

mroute

- multicast routing cache entry.

mrule

- rule in multicast routing policy database.

neighbour

- manage ARP or NDISC cache entries.

netns

- manage network namespaces.

ntable

- manage the neighbor cache’s operation.

route

- routing table entry.

rule

- rule in routing policy database.

tcp_metrics/tcpmetrics

- manage TCP Metrics

tunnel

- tunnel over IP.

tuntap

- manage TUN/TAP devices.

xfrm

- manage IPSec policies.

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.

reporting bugs

Report bug to the Network Developers mailing list <netdev[:at:]vger.kernel[:dot:]org> where the development and maintenance is primarily done. You do not have to be subscribed to the list to send a message there.


history

ip was written by Alexey N. Kuznetsov and added in Linux 2.2.


see also

ip-address, ip-addrlabel, ip-l2tp, ip-link, ip-maddress, ip-monitor, ip-mroute, ip-neighbour, ip-netns, ip-ntable, ip-route, ip-rule, ip-tcp_metrics, ip-tunnel, ip-xfrm
IP Command reference ip-cref.ps


author

Original Manpage by Michail Litvak <mci[:at:]owl.openwall[:dot:]com>

How can this site be more helpful to YOU ?


give  feedback