Assigning static ip in linux [closed] - linux

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I've tried to assign static ip to my raspberry computer, yet it doesn't assign it after rebooting. My /etc/networ/interfaces file looks like this:
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
#iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
After rebooting and using ifconfig command it shows me that the address is different. What should I do to make it assign data from the file?

It's /etc/network/interfaces not /etc/networ/interfaces and you forgot to add:
auto eth0
iface eth0 inet static
You should do:
/etc/init.d/networking restart
or
ifdown eth0
ifup eth0
Instead of rebooting, Also make sure that 192.168.1.2 isn't used already.

Try changing
auto lo
to
auto lo eth0
As this will make ifup -a run during system startup configure eth0 as well. (see man interfaces).

Related

How to check that IP addess is attched to which eth in Linux Machine? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 years ago.
Improve this question
Well I use SUSE11 Linux machine, Is there is a single cmd which gives the eth number to which my IP is attched to ?
Ex:
<1035 sne-70 [u2see] :/home/u2see/nginrun/log>**ifconfig -a | grep addr**
eth0 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:39
inet6 addr: fe80::225:9eff:fed4:7d39/64 Scope:Link
eth2 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3A
inet addr:192.168.100.70 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::225:9eff:fed4:7d3a/64 Scope:Link
eth3 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3B
inet6 addr: fe80::225:9eff:fed4:7d3b/64 Scope:Link
eth4 Link encap:Ethernet HWaddr 00:25:9E:D4:7D:3C
inet addr:**10.19.120.24** Bcast:10.19.120.255 Mask:255.255.255.0
inet6 addr: 2607:f0d0:1002:11::6/64 Scope:Global
inet6 addr: fe80::225:9eff:fed4:7d3c/64 Scope:Link
My IP is "10.19.120.24" And i need to get the output as eth4 by using single cmd..
What cmd i can use ?
You can use GNU awk:
ifconfig -a |awk -v RS="\n\n" '/inet addr:10.19.120.24 /{print $1}'

Pass IP-address to cloud-init metadata

I am searching for a way to pass a ip-address to cloud-init metadata. So when my qcow boots, it does not have to wait for 120 - 180 seconds to boot.
Currently I've created a workaround by adding IP-address information to the userdata part of cloud-init. The con is, it does take some time because cloud-init userdata is only executed after booting the VM.
echo -e "
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
\taddress $address
\tnetmask $netmask
\tgateway $gateway
\tdns-nameservers $dnsnameservers
" > /etc/network/interfaces
ifdown eth0; ifup eth0
Currently to set the hostname in cloud-init metadata, I've already obtained this part:
cat > $config_dir/meta-data <<-EOF
instance-id: $uuid
hostname: $hostname
local-hostname: $hostname
EOF
But I need something more solid, more concrete because the cloud-init documentation is very vague
EDIT: I've seen that it is possible because Openstack can do it.
It is possible by using the following format:
network-interfaces: |
auto lo
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx (static ip)
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx (gateway ip, usually ip address of router)
You basically write out the configuration you want your interfaces to have as an interfaces file would look as long as you have 'network-interfaces: |'
Hope that answers your question!

How do I restart wlan0 with the static ip instead of a dynamic ip? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 7 years ago.
Improve this question
I have a Raspberry Pi running Raspbian Wheezy. The /etc/network/interfaces is set up to give the Pi a static ip on start up. However, when connection is dropped the Pi won't re-establish a connection automatically. I have a script that restarts wlan0. However, the Raspberry Pi has a different ip address than the static ip given to it. This breaks the port forwarding I’ve done to access the Pi from outside the network.
It looks as if my interfaces is not set up quite right. The Pi can be accessed from two ip addresses within the network, one is the static address I defined while the other is not. When wlan0 is restarted, a dynamic ip address is given to the Pi, but not the static address.
Here is my /etc/network/interfaces:
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet manual
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.11
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid "ROUTER NAME"
wpa-psk "PASSWORD"
auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Here is the script I'm using to reset wlan0:
#!/bin/bash
SERVER=192.168.1.1 #Ping the router
ping -c2 ${SERVER} > /dev/null
#If the exits status from the ping is not 0 (failed)
if [$? != 0]
then
#Disable wlan0 and re-enable it
sleep 2
ifconfig wlan0 down
sleep 2
ifconfig wlan0 up
fi
Any help is appreciated! Thanks!
Edit:
After looking around with ideas found in this thread, I found /etc/init.d/networking restart does everything I need.So the new script is
#!/bin/bash
SERVER=192.168.1.1
ping -c2 ${SERVER} > /dev/null
if [ $?!=0 ]
then
/etc/init.d/networking restart
echo "Reconnecting!"
fi
I looked around a bit and it seems you may be able to make sure it is set in your wifi script after ifconfig wlan0 up (I've also had to implement such a script on every raspberry pi setup I've ever made due to wifi inconsistencies)
if [$? != 0]
then
#Disable wlan0 and re-enable it
sleep 2
ifconfig wlan0 down
sleep 2
ifconfig wlan0 up
ifconfig wlan0 192.168.1.11
fi
Though it should be noted that I personally have never set up a static ip on a pi, I use a reverse tunneling service so I never have to worry about port forwarding. My answer references this answer from the raspberrypi stackexchange site.
https://raspberrypi.stackexchange.com/questions/9678/static-ip-failing-for-wlan0
Let me know if that helps otherwise I can dig deeper into it.
According to feedback from the asker, the /etc/init.d/networking restart was the answer, read comments below.

How to get the gateway MAC address in Unix-like systems [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 2 years ago.
Improve this question
I'm connected to a private network where the IP addresses are like 192.168.xxx.xxx. I know the IP address of the default gateway but how do I get the gateway mac address? I'm working on iMac and Linux machines. Any Unix command for that?
This gives you list of everything:
netstat -rn
or this one to get default gateway:
netstat -rn | grep 'default'
WHAT YOU REALLY WANT:
netstat -rn | grep 'default' | awk '{print $2}'
Here the command line example for arping assuming your gateway's IP address is 192.168.1.1 and you have connected over eth0:
arping -f -I eth0 192.168.1.1
ARPING 192.168.1.1 from 192.168.1.24 eth0
Unicast reply from 192.168.1.1 [ab:cd:ef:01:02:03] 1.030ms
Sent 1 probes (1 broadcast(s))
Received 1 response(s)
So in this case gateway's MAC address is ab:cd:ef:01:02:03

Ubuntu: Reset default routing table [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
On my computer I have 2 connections - 3G and LAN.
Before the 3G is connected the routing table would look like this:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.0.1 0.0.0.0 UG 100 0 0 eth0
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
After the 3G dialup the routing table would look like this:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.64.64.64 0.0.0.0 UG 0 0 0 ppp0
10.64.64.64 * 255.255.255.255 UH 0 0 0 ppp0
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
After the 3G is being disconnected, the routing table would look like this:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.0 * 255.255.255.0 U 0 0 0 eth0
Since the default routing is disabled after the 3G is being disconnected, there is no way for the system to connect to the server, even the LAN is active.
Is there a way I can modify the routing table after the 3G is being disconnected?
Thanks in advance
% sudo route add default gw 192.168.0.1
If the route command is not available, try
% sudo ip route add default via 192.168.0.1

Resources