Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Congratulations on a brilliant idea and a great site..."

Geography

Where in the world do Tek-Tips members come from?

ubuntu configuration issues: gethostbyname & inet_ntoa

whn (Programmer)
18 Apr 12 11:50
Hi Experts,

I need your help in configuring my ubuntu desktop at work.

My company just moved to a new location. And my ubuntu box behaves strangely after the move.

My ubuntu is configured to get a dynamic IP. Before the move, it's dynamic IP was 192.168.5.41. I had kept it's running for weeks, so the IP stayed the same before the move.

After the move, I restarted my ubuntu and the IP changed to 192.168.4.120, which is fine. However, the perl program I wrote before still returns the OLD IP - 192.168.5.41.

I have several ubuntu machines and they are all configured the same (I did not set the ip/hostname in /etc/hosts for all the machines I have). What puzzles me is that only one has this problem!!

Below is the output of 'ifconfig'

CODE

% ifconfig

eth0      Link encap:Ethernet  HWaddr 00:19:bb:df:4d:bd
          inet addr:192.168.4.120  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: fe80::219:bbff:fedf:4dbd/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1587653 errors:11 dropped:0 overruns:0 frame:31
          TX packets:337638 errors:0 dropped:0 overruns:0 carrier:0
          collisions:244622 txqueuelen:1000
          RX bytes:778624182 (778.6 MB)  TX bytes:54320583 (54.3 MB)
          Interrupt:17

Below is my small testing perl code:

CODE

#! /usr/bin/perl

use strict;
use warnings;
use Sys::Hostname;
use Socket;

my $host = hostname;
print "\$host = $host\n";
my @tmp = gethostbyname($host);
my $x = join ',', @tmp;
print "\$#tmp = $#tmp\n";
print "\$x = $x\n";
#my($ip) = inet_ntoa( (gethostbyname($host))[4] );
my $tt = (gethostbyname($host))[4];
my($ip) = inet_ntoa($tt);
print "$0.. \$ip = $ip\n";
exit;

Below is the test run of my perl code:

CODE

% ./getLocalIP.pl
$host = orion
$#tmp = 4
$x = orion.mycompany.com,,2,4,ˬ)
PuTTY./getLocalIP.pl.. $ip = 192.168.5.41
% PuTTY

My questions:

1) Again, why does it return the old ip? This cannot be a random thing!!
2) why does gethostbyname() return some kind of trash (in red)?
3) why do I see 'PuTTY' here? I am using Putty on a win 7 machine to connect to the ubuntu in question.

Many thanks in advance for the help!!!

 
FlorianAwk (Programmer)
20 Apr 12 13:57
What gives

CODE

echo $HOSTALIASES
?
whn (Programmer)
20 Apr 12 14:12
The variable is not set.

CODE

% echo $HOSTALIASES

%

However, not sure if the piece of info below could indicate something:

CODE

arp
Address                  HWtype  HWaddress           Flags Mask            Iface
bguild02.local           ether   b8:8d:12:0e:00:48   C                     eth0
Quetzal.local            ether   28:cf:da:eb:98:e8   C                     eth0
ggreenbaum-xp.mycompany  ether   64:31:50:37:68:05   C                     eth0
192.168.5.41                     (incomplete)                              eth0
192.168.4.2              ether   c8:4c:75:ea:39:42   C                     eth0

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close