How to force the same internal IP address?

edited May 2011 in Tech & Games
Right, so I've got something set up on my computer which needs a port open. To open a port, you have to assign it to a specific internal IP address, like this...

xr.png

Only problem is, whenever I reboot my computer, it will assign it a different internal IP address which doesn't match with the configuration which you can see above. I then have to go into the router configuration and then change the IP address which is in the box.

This gets freakin' annoying.

So, is there any way to force the use of the same internal IP address all the time?

Comments

  • SpiffSpiff Regular
    edited May 2011
    Simple answer. Disable DHCP
  • DfgDfg Admin
    edited May 2011
    Disable DHCP if you want or set DHCP to just hand out one IP address.
    Like; Start IP 192.168.1.2 End Ip 192.168.1.2

    or you can go into Windows Adaptor setting and set static IP.


    I have disabled DHCP on my router and set Internal IP manually and then opened the port using Virtual Servers.
  • BaconPieBaconPie Regular
    edited May 2011
    There is a Dynamic Host Control Protocol server running on your router. Whenever a device gets on the network it says "Hey, I need an IP address!" and your router goes, "K, let me check my DHCP table for free IP addresses". It finds one and tells your computer to use it. This means that you can't really tell what IP address you'll get each time you request a free one from the router.

    There are two ways around this. The complicated way, were you tell the DHCP server to always reserve the one IP address to a certain MAC address or the easy way, tell the DHCP server to never give out a certain range of IP addresses and then, instead of asking the server for a free IP, assign yourself one. This is called a static IP address.

    The way I have it set up is so that the DHCP server (my router) only gives out addresses above 192.168.0.10. Then I say to my network card, you're IP address is 192.168.0.3 with:
    # ifconfig eth0 192.168.0.3 netmask 255.255.255.0
    # route add default gw 192.168.0.1
    

    Which says, interface eth0 has the IP address 192.168.0.3 and it's subnet is in the 192.168.0 domain (that's the subnet mask bit - it's a logical AND with your IP address). Then I say, all traffic goes through 192.168.0.1 (my default gateway).

    The details of how to do this on boot differ between operating systems but on a linux machine, that's how you would do it while the system is up. To request an IP address using DHCP you can type:
    # dhcpcd eth0
    

    And that will sort everything out for you, but, like we mentioned at the beginning, this won't get you a static IP.

    Also, this might be of interest. You can edit your hosts file (/etc/hosts on linux) of any other computers you may have so that you can type in the name of your computer instead of 192.168.0.3. For example, my host's file:
    $ cat /etc/hosts
    #
    # /etc/hosts: static lookup table for host names
    #
    
    #<ip-address> <hostname.domain.org> <hostname>
    127.0.0.1     localhost.localdomain localhost kiwi
    ::1           localhost.localdomain localhost kiwi
    
    192.168.0.1                         skynet
    192.168.0.2                         terminator
    

    Skynet and Terminator are our to routers. :)
  • edited May 2011
    I realized that there was a setting in my router which allows for IP address reservation. I set my computer to have a reserved IP address, which will do what I need :) Thanks for the help though.
Sign In or Register to comment.