sudo ifconfig eth0 192.168.1.7 netmask 255.255.255.0 not permanent
You need to edit /etc/network/interfaces
to keep it permanently, something like this:
auto eth0
iface eth0 inet static
address 192.168.1.7
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
Related videos on Youtube
liv2hak
Updated on September 18, 2022Comments
-
liv2hak almost 2 years
I have two PC's and a series of Juniper EX-2200 switches connected to form a network.None of the devices are connected to any external network.If I do an ifconfig on the first PC (monitor) I see that that PC only has an ethernet address.It does not have an IP address.I want to use an IP address to use applications such as scp.
So I do the following.
sudo ifconfig eth0 192.168.1.7 netmask 255.255.255.0
Now if I do an ifconfig the PC shows the IP address of 192.168.1.7 as expected.However it does n't seem to retains the IP address.It seems to lose the IP address after some time.I never rebooted the PC.It is likely that I am receiving ARP traffic on this PC.Can that cause the PC to lose the IP address.If yes,How can I cause the PC to retain the IP address
The route -n on the PC produces the following lines.
Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 169.254.0.0 0.0.0.0 255.255.255.0 U 1000 0 0 eth0 192.168.1.0 0.0.0.0 255.255.254.0 U 0 0 0 eth0
It looks like the default gateway in this case is 0.0.0.0
-
Greg Petersen almost 12 yearsWhich distro your PC is running?
-
liv2hak almost 12 yearsI am using Ubuntu 12.04 :)
-
-
liv2hak almost 12 yearscan I give the gateway address (192.168.1.1) as dummy.Or do I need to have a machine with that IP in the network?
-
liv2hak almost 12 yearsand afterwards do I need to restart the script or something?
-
Greg Petersen almost 12 years1. What is your current default gateway
route -n
? 2. Restart the network to make it take effect:sudo /etc/init.d/networking restart
. -
liv2hak almost 12 yearsroute -n outputs two lines with Destination Gateway Genmask values.Both the lines have Gateway (0.0.0.0)
-
Greg Petersen almost 12 yearsjust change the
gateway
line to0.0.0.0
, basically it means "anything".