On my LAN there are multiple DHCP servers running, and all of them are on the same range.
Now I use a machine which has a dynamic IP address from a DHCP server. I have to know from which server it comes.
How to do that?!
On my LAN there are multiple DHCP servers running, and all of them are on the same range.
Now I use a machine which has a dynamic IP address from a DHCP server. I have to know from which server it comes.
How to do that?!
To find out the DHCP server that's giving you the IP, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:
cat /var/lib/dhcp3/dhclient.leases
Or you can just use grep command to get DHCP server address.
grep dhcp-server-identifier /var/lib/dhcp3/dhclient.leases
OR
grep dhcp-server-identifier /var/lib/dhcp/dhclient.leases
For Ubuntu 14.04, 16.04, and 17.10 you can use:
dhclient -d -nw eth0
Sample output:
Internet Systems Consortium DHCP Client 4.2.4
Copyright 2004-2012 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/00:0c:29:49:3e:67
Sending on LPF/eth0/00:0c:29:49:3e:67
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3 (xid=0x4f723f9)
DHCPREQUEST of 192.168.138.136 on eth0 to 255.255.255.255 port 67 (xid=0x4f723f9)
DHCPOFFER of 192.168.138.136 from 192.168.138.254
DHCPACK of 192.168.138.136 from 192.168.138.254
RTNETLINK answers: File exists
bound to 192.168.138.136 -- renewal in 892 seconds.
In Ubuntu 14.04, the /var/lib/dhcp/dhclient.leases is empty. The actual lease file can be found on the command line of dhclient via ps. Look for the -lf option. This command should work in Ubuntu 14.04 installations (still valid as of 17.10):
cat $(ps aux | grep -o '[/]var/lib/NetworkManager/\S*.lease') | grep dhcp-server-identifier
With:
sudo nmap --script broadcast-dhcp-discover -e eth0 # DHCPv4
sudo nmap --script broadcast-dhcp6-discover -6 # DHCPv6
sudo dhcpdump -i eth0
sudo tcpdump -i eth0 -nev udp port 68
Others:
dhcp_probe (dhcp-probe package)Using the new iproute2 (in my case in Ubuntu 22.04.1 LTS):
$ ip route | grep default
default via 1xx.1xx.xxx.xxx dev gpd0 metric 10
default via 192.168.xxx.xxx dev wlp0s proto dhcp metric 100
The DHCP server IP is the one given after the via keyword for each of your specified network interface(s).
ip r | grep default also works.
From the man:
ip route
Show table routes.
The help:
$ ip route help
$ ip route help
Usage: ip route { list | flush } SELECTOR
ip route save SELECTOR
ip route restore
ip route showdump
ip route get [ ROUTE_GET_FLAGS ] ADDRESS
[ from ADDRESS iif STRING ]
[ oif STRING ] [ tos TOS ]
[ mark NUMBER ] [ vrf NAME ]
[ uid NUMBER ] [ ipproto PROTOCOL ]
[ sport NUMBER ] [ dport NUMBER ]
ip route { add | del | change | append | replace } ROUTE
SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]
[ table TABLE_ID ] [ vrf NAME ] [ 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 ]
[ ttl-propagate { enabled | disabled } ]
INFO_SPEC := { NH | nhid ID } OPTIONS FLAGS [ nexthop NH ]...
NH := [ encap ENCAPTYPE ENCAPHDR ] [ via [ FAMILY ] ADDRESS ]
[ dev STRING ] [ weight NUMBER ] NHFLAGS
FAMILY := [ inet | inet6 | mpls | bridge | link ]
OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ]
[ rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ]
[ window NUMBER ] [ cwnd NUMBER ] [ initcwnd NUMBER ]
[ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]
[ rto_min TIME ] [ hoplimit NUMBER ] [ initrwnd NUMBER ]
[ features FEATURES ] [ quickack BOOL ] [ congctl NAME ]
[ pref PREF ] [ expires TIME ] [ fastopen_no_cookie BOOL ]
TYPE := { unicast | local | broadcast | multicast | throw |
unreachable | prohibit | blackhole | nat }
TABLE_ID := [ local | main | default | all | NUMBER ]
SCOPE := [ host | link | global | NUMBER ]
NHFLAGS := [ onlink | pervasive ]
RTPROTO := [ kernel | boot | static | NUMBER ]
PREF := [ low | medium | high ]
TIME := NUMBER[s|ms]
BOOL := [1|0]
FEATURES := ecn
ENCAPTYPE := [ mpls | ip | ip6 | seg6 | seg6local | rpl | ioam6 ]
ENCAPHDR := [ MPLSLABEL | SEG6HDR | SEG6LOCAL | IOAM6HDR ]
SEG6HDR := [ mode SEGMODE ] segs ADDR1,ADDRi,ADDRn [hmac HMACKEYID] [cleanup]
SEGMODE := [ encap | inline ]
SEG6LOCAL := action ACTION [ OPTIONS ] [ count ]
ACTION := { End | End.X | End.T | End.DX2 | End.DX6 | End.DX4 |
End.DT6 | End.DT4 | End.DT46 | End.B6 | End.B6.Encaps |
End.BM | End.S | End.AS | End.AM | End.BPF }
OPTIONS := OPTION [ OPTIONS ]
OPTION := { srh SEG6HDR | nh4 ADDR | nh6 ADDR | iif DEV | oif DEV |
table TABLEID | vrftable TABLEID | endpoint PROGNAME }
IOAM6HDR := trace prealloc type IOAM6_TRACE_TYPE ns IOAM6_NAMESPACE size IOAM6_TRACE_SIZE
ROUTE_GET_FLAGS := [ fibmatch ]
Current version:
$ ip -V
ip utility, iproute2-5.15.0, libbpf 0.5.0
More:
Web: https://wiki.linuxfoundation.org/networking/iproute2
Git.kernel: https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
Github: https://github.com/shemminger/iproute2