Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ubuntu configuration issues: gethostbyname & inet_ntoa

Status
Not open for further replies.

whn

Programmer
Oct 14, 2007
265
US
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:[b][COLOR=red]192.168.4.120[/color][/b]  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,[b][COLOR=red]ˬ[/color][/b])
[b][COLOR=red]PuTTY[/color][/b]./getLocalIP.pl.. [b]$ip = 192.168.5.41[/b]
% [b][COLOR=red]PuTTY[/color][/b]

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!!!

 
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
[b][COLOR=red]192.168.5.41                     (incomplete)                              eth0[/color][/b]
192.168.4.2              ether   c8:4c:75:ea:39:42   C                     eth0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top