Network setup

Tom H tomh0665 at gmail.com
Thu Jan 14 13:28:27 UTC 2016


On Thu, Jan 14, 2016 at 1:18 PM, Chris Green <cl at isbd.net> wrote:
> On Thu, Jan 14, 2016 at 12:47:25PM +0100, Tom H wrote:
>>>
>>> Have you looked at ifconfig?
>>
>> Please don't.
>>
>> 1) "ip" is the tool to use for manual NIC configuration; "ifconfig"
>> has been deprecated for a while.
>>
> That's all very well but ifconfig is much handier still.
>
> At a very basic level if I just type 'ifconfig' at the command line I
> get a useful summary of my network devices and their status. If I
> type 'ip' at the command line I get a decidedly complex looking list
> of options and no useful output at all.
>
> It's not even very obvious from the default help given by 'ip' how I
> would simply ask for the same information that 'ifconfig' gives me.

Using ip:

# root at rr:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: wired0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP group default qlen 1000
    link/ether 08:00:27:7a:ab:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.222/24 brd 192.168.1.255 scope global dynamic wired0
       valid_lft 80585sec preferred_lft 80585sec

# ip a sh dev wired0 | grep "inet "
    inet 192.168.1.222/24 brd 192.168.1.255 scope global dynamic wired0

ip a == ip address (where "show" is assumed)
ip a sh == ip address show ("show" is needed when you want to specify
a NIC with "dev ...")

Using nmcli (to get the ipv4 settings):

v0.9.8
nmcli -f IP c sh id "$(nmcli -t -f NAME c st)"

v0.9.10
nmcli -f IP4 c sh id "$(nmcli -t -f NAME c sh --active)"

On a 16.04 VM:

# nmcli -f IP4 c sh id "$(nmcli -t -f NAME c sh --active)"
IP4.ADDRESS[1]:                         192.168.1.222/24
IP4.GATEWAY:                            192.168.1.1
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP4.DOMAIN[1]:                          city

So you get the equivalent of "cat /etc/resolv.conf" too.

"nmcli -t -f NAME c sh --active" is to get the name of the connection.
Somewhat confusingly, you feed the "NAME" field to the "id" key:

# nmcli c sh
NAME      UUID                                  TYPE            DEVICE
wired0nm  8d3ed639-e9e1-3018-ac2e-e38f1239b62e  802-3-ethernet  wired0

c == connection
sh == show

# nmcli -f IP4 c sh id wired0nm
IP4.ADDRESS[1]:                         192.168.1.222/24
IP4.GATEWAY:                            192.168.1.1
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP4.DOMAIN[1]:                          city

or

# nmcli -f IP4 c sh uuid 8d3ed639-e9e1-3018-ac2e-e38f1239b62e
IP4.ADDRESS[1]:                         192.168.1.222/24
IP4.GATEWAY:                            192.168.1.1
IP4.DNS[1]:                             8.8.8.8
IP4.DNS[2]:                             8.8.4.4
IP4.DOMAIN[1]:                          city

So my script could've been 'nmcli -f IP4 c sh uuid "$(nmcli -t -f UUID
c sh --active)"'.

You can just output the ip address (or any of the above fields):

# nmcli -f IP4.ADDRESS c sh uuid "$(nmcli -t -f UUID c sh --active)"
IP4.ADDRESS[1]:                         192.168.1.222/24

Note that I'm using "-f IP4" to limit the output to IP4 settings.
Again, confusingly, ipv4 is different from IP4:

# nmcli -f ipv4 c sh uuid "$(nmcli -t -f UUID c sh --active)"
ipv4.method:                            auto
ipv4.dns:
ipv4.dns-search:
ipv4.addresses:
ipv4.gateway:                           --
ipv4.routes:
ipv4.route-metric:                      -1
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.never-default:                     no
ipv4.may-fail:                          yes

Pre-v0.9.10, "nm-tool" was used to display NM settings without having
to figure out "nmcli" options but it was obsoleted.



More information about the ubuntu-users mailing list