Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

DHCP client/server

Posted on 2008-06-25
1
Medium Priority
?
224 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 1500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

704 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