Solved

DHCP client/server

Posted on 2008-06-25
1
214 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
Comment Utility
>  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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now