Solved

DHCP client/server

Posted on 2008-06-25
1
216 Views
Last Modified: 2010-05-18
Hello, I'm developing one application on Linux machine. I need to make dhcp request two times using some shell script.
For first time I need to makean  request to dhcp server using dhclient to get IP address.
Question: How can  use dhclient to make such request and if client gets IP and how can I get that IP.
after second time, I again need to make dhcp request. This time I need other parameters also (like IP of Http server etc) along with IP address/subnet mask ..etc. IP address of HTTP server and other optional parameters are configured on dhcp server... I just need to make request to get them.
How can I achieve this.
Plz advise
0
Comment
Question by:pkgoyal
1 Comment
 
LVL 27

Accepted Solution

by:
Nopius earned 500 total points
ID: 21896058
>  I need to make dhcp request two times using some shell script.

Read:
man dhclient
man dhclient-script
man dhclient.conf

> For first time I need to makean  request to dhcp server using dhclient to get IP address.

Create /etc/dhclient-up-hooks file and make it executable.
It will look like:
#!/bin/bash
#
# Look here to see all variables you may use, like '$reason' or '$new_ip_address'
# also read man dhclient-script
env > /tmp/dhclient.txt

# That's a real code
case $reason in
  BOUND)
      echo My new IP address is $new_ip_address
      ;;
esac

To request new IP address (only then your dhclient-up-hook triggers), run as root:

# dhclient eth0

> after second time, I again need to make dhcp request. This time I need other parameters also (like IP of Http server etc) along with IP address/subnet mask ..etc. IP address of HTTP server and other optional parameters are configured on dhcp server...

Now add more logic inside your dhclient-up-hook
case $reason in
  BOUND)
      echo My new IP address is $new_ip_address
      ;;
  RENEW)
      echo Subnet: $new_subnet_mask
      ;;
esac
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question