Solved

DHCP client/server

Posted on 2008-06-25
1
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
linux, squid, exchange 14 186
IPA and Samba (and NFS and Samba....) 1 156
iptables ubuntu BLOCK all 2 97
Lost connection with ALL workstations on LAN 7 48
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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