Linux get dhcp leases

Find DHCP Lease & DNS Info In 18.04 LTS

I’m relatively new to Linux and Ubuntu, so please bear with me. I’m setting up a Ubuntu 18.04 LTS VM that will act as a mail relay via postfix. I have that installed, and have configured those settings to match the old existing relay server that was set up years ago, at least as much as I can determine. My issues is, the connection from this new relay server is timing out, which I can see in the /var/log/mail.log file. This server is set up to obtain an IP via DHCP because of the way our network is set up. I work for a group that is affiliated with a university, but we’re not directly part of the IT staff, so my group has their own IT department, of which I’m a part. In order to get anything on the University’s network, we have to register the MAC address of the device, then once that registration is complete with the uni, they assign an IP address and the device gets a lease. What I can’t figure out is two-fold: first, how to look up what my lease information is. Second, in conjunction with that, how I can see what DNS servers are included with that lease. I’ve used a number of commands to try and look that information up, or glean it from Ubuntu in some way, but to no avail. I also have the Ubuntu desktop installed, as that was something the previous mail relay server had, just so I could be as 1:1 with my setup as possible, and I can’t find any info via the Network section of the system settings either. I looked through http://manpages.ubuntu.com/manpages/bionic/en/man1/ for anything with ‘dhcp’ or ‘dns’ in the list, but couldn’t seem to find a command I could throw at it to determine the answer to my question. The other curious thing is, my network interface is labeled ‘ens160’ instead of ‘eth0’, which I thought was odd. In any event, I’m trying to determine what my DHCP and DNS info is, because I can ping some hostnames inside and outside the network, but I might be missing some internal DNS server entries, in which case, I’ll need to know how to add those, but I also want to make sure I can clearly see what my setup is. Unfortunately, ifconfig doesn’t return much more than the IP, MAC, and interface name info. Anyway, sorry for the novella, but I’m just trying to figure out how to see the full networking details on my new server, so I can better troubleshoot the issue at hand.

Читайте также:  Intel haswell drivers linux

Your interface name is because of the «predicable interface names» change a few years ago. I think you should be able to check lease information with netplan ip leases ens160 , however it is currently broken for dhcp. 18.04 changed to netplan, and all of this stuff is different.

Looks like I actually got some results with netplan ip leases ens160 so thanks for that. If I need to add additional DNS servers for this system to use, will that still be in /etc/network/interfaces or is there a different location for that in 18.04 LTS? And if I specify the servers that are already in there, but I place my own internal DNS ahead of that in the file, will it prefer the DHCP DNS entries, or the order of the servers I create in that file?

well, /etc/network/interfaces is used by ifup and ifdown, which are no longer supposed to be used on 18.04. The yet to be published network updates to the Ubuntu Serverguide does not have a dhcp DNS override example. See if the DNS setting examples here for static can be applied to a dhcp yaml config file.

Источник

Check my DHCP lease?

Is there a way to show my current (client) DHCP lease? Or even better — retrieve all options/infos sent with DHCPACK ?

@heemayl this file is empty in my case (Ubuntu 15.10), maybe because NetworkManager is acquiring dhcp lease (?)

@heemayl was correct for the directory. On Debian Stretch I found infos in «/var/lib/dhcp/dhclient.eth0.leases»

9 Answers 9

I’m not aware of a way to query this information on the client. If you are on the server you can see information on the client leases in /var/lib/dhcp/dhclient.leases . From the client the only way i know is:

sudo grep dhclient /var/log/syslog 

Which should give you something like:

May 20 18:34:38 [machine_name] dhclient: DHCPREQUEST on eth0 to [DHCP_SERVER_IP] port 67 May 20 18:34:38 [machine_name] dhclient: DHCPACK from [DHCP_SERVER_IP] May 20 18:34:38 [machine_name] dhclient: bound to [client_dhcp_ip] -- renewal in 1517 seconds. 

depending on your distro, it should be located in /var/lib/dhcp under dhclient..leases or /var/lib/dhclient.leases . you can also specify the path of your dhclient.leases file by passing -lf when starting dhclient.

Читайте также:  Ftp server setup in linux

With NetworkManager use nmcli to query the DHCP status for your active connection (assuming one) with

nmcli -f ipv4.method con show "`nmcli -t -f NAME connection `" 

For full DHCP information use -f DHCP4 . Adjust for ipv6 as necessary.

This prints the DHCP information for the currently active connection: nmcli -f DHCP4 con show «$(nmcli -g NAME con show —active)»

I used dhcpdump when I was testing DHCP. It will dump both sides of the DHCP transaction. If you leave it running it will log the options passed.

You may want to restart your DHCP client to see the initial negotiation. The renewal request should contain all the running configuration.

There is one other aspect to this answer to consider to show your DHCP lease time and other DHCP information in the offer. If using Linux systemd-networkd, none of the options above work as they relate to network manager (the Linux solutions at least)

There is a similar question with answer explaining this at How do I check DHCP lease time in systemd-networkd?

Depending on the OS; Enabling debug isn’t always necessary.

systemd-networkd should store the lease info under /run/systemd/netif/leases/

i.e.

cat /run/systemd/netif/leases/2 

Check Which Lease.

If you thought this couldn’t get anymore confused, you’d be wrong 😉

I found this question unpicking my own DHCP issues on Ubuntu 22.04 Desktop edition, where I discovered that I actually had TWO leases!:

sudo cat /var/lib/dhcp/dhclient.leases sudo cat /var/lib/NetworkManager/internal-d6b936ad-d73f-4898-a826-edbb61d6155a-eth0.lease 

So which is the one being used.

(2) DHCP Clients:

Unlike Ubuntu’s LTS server flavour, their Desktop edition winds-in NetworkManager into the networking gears.

Determine Default DHCP Client

So, there’s (2) DHCP clients in this case, but which of these are actually being used?

In Ubuntu Networking, there is a layer of abstraction called netplan which sets the default networking gears in the directive renderer .

A review of /etc/netplan/01-network-manager-all.yaml reveals that NetworkManager is controlling our networking, NOT systemd-networkd.

A review of NetworkManager’s logging:

 journalctl -u NetworkManager.service | grep DHCP 

reveals that NetworkManager is using its’ own DHCP client:

NetworkManager[5117]: [1655970837.0088] dhcp-init: Using DHCP client 'internal'. 

Thus, of our (2) leases, the one being used by the system is:

/var/lib/NetworkManager/internal-d6b936ad-d73f-4898-a826-edbb61d6155a-eth0.lease 

Note the keyword in that log message is «using«: even if a gazillion DHCP clients are shown in the logging as enabled , only the one specified as «using» is the active DHCP client.

Читайте также:  Linux расширить раздел ext4

Wow, this was a tangle; hope this saves others going down the same deep, dark rabbit hole.

Источник

Agava80 IT knowledge base

В Debian:
Информация о выданных адресах хранится в:
dhcpd.leases внутри каталога /var/lib/dhcp/dhcpd.leases
Открываем файл с помощью «cat» и смотрим, кто что получил.

В CentOS:
cd /var/lib/dhcpd
cat dhcpd.leases
OR TO EDIT
nano dhcpd.leases

  • Получить ссылку
  • Facebook
  • Twitter
  • Pinterest
  • Электронная почта
  • Другие приложения

Комментарии

Отправить комментарий

Популярные сообщения из этого блога

Получение доступа к серверу SQL при отсутствии пароля администратора SQL.

Столкнулся я тут с проблемой: после смены пароля от учетной записи, из под которой работал сервер централизованного управления «Kaspersky Security Center 10», данная служба перестала работать. Подменили учётную запись, из под которой запускается служба приложения — безрезультатно. В итоге выяснили, что проблема уходят корнями в «Microsoft SQL Server», доступ к которому также осуществлялся из под этой УЗ. Чтобы сменить УЗ, из под которой «Kaspersky Security Center 10» «ломится» к базе данных, нужны административные права от «Microsoft SQL Server», которых ни у локального администратора ни у доменных администраторов не оказалось. ВНИМАНИЕ: ВСЕ КОМАНДЫ НУЖНО ЗАПУСКАТЬ ИЗ ПОД «CMD» или «Poweshell», которые в свою очередь запущены с повышением прав. (Правой кнопкой мыши на запускаемом приложении и далее, ЗАПУСТИТЬ ОТ АДМИНИСТРАТОРА). В итоге, пришлось запускать базу данных в специальном режиме: 1) Останавливаем э

Макросы объединения ячеек в EXEL.

Иногда бывает необходимо провести объединение ячеек в EXEL. Стандартно и просто EXEL этого делать не умеет. Нужно писать макросы. Вот два из них. 1) Данный макрос объединяет данные из выделенных ячеек в одну. Sub MergeToOneCell() Const sDELIM As String = » » ‘символ-разделитель Dim rCell As Range Dim sMergeStr As String If TypeName(Selection) <> «Range» Then Exit Sub ‘если выделены не ячейки — выходим With Selection For Each rCell In .Cells sMergeStr = sMergeStr & sDELIM & rCell.Text ‘собираем текст из ячеек Next rCell Application.DisplayAlerts = False ‘отключаем стандартное предупреждение о потере текста .Merge Across:=False ‘объединяем ячейки Application.DisplayAlerts = True .Item(1).Value = Mid(sMergeStr, 1 + Len(sDELIM)) ‘добавляем к объед.ячейке суммарный текст End With End Su 2) Данный макрос об

Источник

Оцените статью
Adblock
detector