Solved

DHCP client/server

Posted on 2008-06-25
1
218 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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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