how to change ip address in the correct way on linux?

0

I'm working with wheezy.

I have configured the /etc/network/interfaces file so that the wlan gets the ip address from the dhcp server.

after that I have imposed a different static ip address in the interfaces file.

First problem: everytime I reboot the machine it gets always the old address, the one that the dhcp server gave to it. I tryed to remove the leases from /var/lib/dhcp/*leases but when it reboots the leases file reappears and in it the old lease as well.

second problem: if I force to change ip address using ifconfig on the interface it works but I have 2 different ip addresses on the same wlan, one is the new ip address and the other is the one given by the dhcp server.

any idea to solve these problems?

Last configuration:

 auto lo eth0
 iface lo inet loopback

 iface eth0 inet static
    address 192.168.1.150
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    #gateway 192.168.1.10

    post-up route add default gw 192.168.1.10 eth0
    pre-down route del default gw 192.168.1.10 eth0


  allow-hotplug wlan2
  auto wlan2
 iface wlan2 inet manual
    #wireless-essid "dlink"
    address 192.168.1.130
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    #gateway 192.168.1.20

    pre-up wpa_supplicant -B w -D wext -i wlan2 -c /etc/wpa_supplicant/wpa_$
    post-down killall -q wpa_supplicant

    post-up route add default gw 192.168.1.20 wlan2
    pre-down route del default gw 192.168.1.20 wlan2

    iface default inet dhcp

wpa_supplicant:

 ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
 update_config=1

network={
    ssid="dlink"
    proto=WPA RSN
    key_mgmt=WPA-PSK
    pairwise=CCMP TKIP
    group=CCMP TKIP
    psk=wpapassword
}

here the ifconfig -a output:

eth0      Link encap:Ethernet  HWaddr c8:a0:30:b2:8c:89
      inet addr:192.168.1.150  Bcast:192.168.1.255  Mask:255.255.255.0
      inet6 addr: fe80::caa0:30ff:feb2:8c89/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:3967 errors:0 dropped:2 overruns:0 frame:0
      TX packets:3202 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:442495 (432.1 KiB)  TX bytes:345005 (336.9 KiB)
      Interrupt:56

lo        Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:2 errors:0 dropped:0 overruns:0 frame:0
      TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:190 (190.0 B)  TX bytes:190 (190.0 B)

wlan2     Link encap:Ethernet  HWaddr 80:1f:02:9b:bd:bf
      inet addr:192.168.1.77  Bcast:192.168.1.255  Mask:255.255.255.0
      inet6 addr: fe80::821f:2ff:fe9b:bdbf/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:962 errors:0 dropped:0 overruns:0 frame:0
      TX packets:21 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:135034 (131.8 KiB)  TX bytes:3622 (3.5 KiB)

Gappa

Posted 2013-06-24T14:39:25.100

Reputation: 113

Are you sure that you are not configuring virtual devices, (ex eth0:1) ? – Edorka – 2013-06-24T14:42:00.530

1yes I'm, I'll post my configuration – Gappa – 2013-06-24T15:09:19.190

why auto wlan2 iface wlan2 inet manual i whould commet that line – Edorka – 2013-06-24T15:14:39.967

auto indicates that the interface has to be loaded during startup, isn't it? anyway I tryed to comment that line but nothing changed – Gappa – 2013-06-24T15:24:42.563

Maybe there is another dhcp client running – Edorka – 2013-06-24T20:19:23.847

Would you post an ´ifconfig -a´ ? Perhaps it will give us some clues. – Edorka – 2013-06-25T06:38:11.713

added the ifconfig -a output – Gappa – 2013-06-25T07:13:06.317

you don't have 2 ips on the same interface, simply you are connecting to the same network thought 2 diferent links – Edorka – 2013-06-25T07:18:52.263

I can see 2 ips on the same interface(wlan) if I use ifconfig to change the wlan ip. I cannot see that from ifconfig output but from another program that sends broadcast udp datagrams and when the device answers it does with 3 ips: 1 on eth0 and 2 on the wlan2 – Gappa – 2013-06-25T07:29:20.663

ummmm ok so the issue is with broadcasting UDPs but that program should be wrong because ifconfig never lies. Does the same if you disconnect eth0 ? – Edorka – 2013-06-25T07:36:11.103

eheh I cannot say if ifconfig never lies but something is wrong because if I write something correct in the interfaces file I expect that that configuration takes place at the next reboot. Anyway yes the same thing with the eth0 disconnected. – Gappa – 2013-06-25T07:45:45.807

Answers

0

You should add the required ip adress in your dhclient.conf file. Read the Sample section of the man page found here.

You would add the following

alias {
  interface "wlan0";
  fixed-address 192.5.5.213;
}

The dhclient will read this file before reading any other config-files.

If you set your ip-adress manualy on the command-line, you could tell dhclient -r to release the lease before setting new ip-adress.

Read more about dhclient here.

Marco M. von Hagen

Posted 2013-06-24T14:39:25.100

Reputation: 495