Is there a way to persist the following command across reboots on Linux RHEL 6 (other than perhaps creating an init.d script):
ifconfig lo multicast
I have an application that requires multicast on 127.0.0.1, and I was wondering whether there's something in /etc/sysconfig/network-scripts that can help persist the ifconfig lo multicast across reboots.
Thanks in advance.
Thanks for the /etc/rc.local suggestion; it would work, and it's technically not an init.d script, so in my humble opinion, the -1 is a bit unfair. However, I'd like to avoid that route if possible in order to improve the maintenance of the file.
After some digging around, I couldn't find any files in the /etc/sysconfig/network-scripts/ that could help; however, I did find a potential solution; after tracing the ifup scripts, there's a hook to invoke an ifup-${DEVICE} file; since that doesn't exist for lo, I've created an ifup-lo file with 755 permissions as follows:
/etc/sysconfig/network-scripts/ifup-lo
# ifconfig is deprecated; use ip link instead...
/sbin/ip link set lo multicast on
/sbin/ip link set lo up
This will be invoked by the os when ifup lo is called, allowing any custom hooks to be added.
Any better solutions are appreciated.
The ideal solution would be for Redhat to add a MULTICAST=on or MULTICAST=off variable in the /etc/ifcfg-lo , but since that's not currently in place, ifup-lo will do for now...
append ifconfig lo multicast to the end of /etc/rc.local
Related
I have a linux box connected to a router via an ethernet cable.
The cable is never unplugged and the linux box is always on.
My goal is to have a command executed on the linux box every time the router is rebooted.
This question is quite similar to this question but the suggested solution doesn't seem to work.
More specifically:
the command
inotifywait -e modify /sys/class/net/eth0/carrier; echo 'Change detected' does never detect a change (even in the case the cable is unplugged from the pc), because according to this answer the command inotifywait does not work in /sys
the command (suggested in a comment) inotifywait -e modify /etc/network/if-up.d/avahi-daemon does not detect any change when the router is rebooted
You can start a script after the linux box gets connected using up
(requires ifplugd to be installed )
#/etc/network/interfaces
auto eth0
iface eth0 inet dhcp
up /etc/network/yourscript.sh
However, there keep in mind that if you disconnect the cable (and plug in in after a while), the script also starts even though the router might not have been restarted.
--edit--
alternatively , place your script in
/etc/network/if-up.d/
(make sure it is executable and restart networking after changes.)
Depending on the Linux distribution on that router the correct way of running a command at startup/reboot is to create a startup script, or add the command to /etc/rc.local
What is the best way to programmatically reload the network settings from the config file /etc/network/interfaces ?
At the moment I use the system command to execute ifdown and ifup on the interface, but i'm not happy with this solution.
being more specific would help ...
but,
maybe you could write some script passing the interfaces as parameters
and turning it down and up, the usual way to re-read the /etc/network/interfaces file is that (I think so).
for interface in $#
do
sudo ifdown ${interface} && sudo ifup ${interface}
done
I have tried nmap, nbtscan, fping, arp-scan for the overstated need and all are producing expected output.
But I am facing some trouble with the arp command its not working and showing something like this:
? (10.240.253.2) at 80:a1:d7:7c:22:94 [ether] on eth0
<something>.local (10.240.253.53) at 9c:2a:70:d8:50:ed [ether] on eth0
I have tried arp -a and arp -a -n both. Also I tried running ping -b <broadcast ip address> before these command but ping -b does not execute at all means it does nothing.
On other systems in my network it is running fine. But it seems there is some setting problem with my computer that I am not aware of.
arp is not a scanner. It queries your system's ARP cache.
Therefore, it will only show IP and MAC addresses of hosts which have sent ARP queries or answers recently seen by your system.
As you mention, nmap, for example, is much more suited to what you're trying to do than arp.
So, I'm trying to write a simple bash script to send my internal IP address to a website of mine on startup. I am on a network with DHCP, so I don't always know what the IP address of my Raspberry Pi will be after I do a reboot over ssh. I figured I could fix this by sending my website the current IP on startup. I haven't written many bash scripts, and I'm not really sure how to send data to my website. Right now I was just trying in the terminal this:
wget -qO- http://http://mywebsite.com/private/CurrentIP.php?send=$(/sbin/ifconfig eth0|grep 'inet addr:')
But I'm not having any luck. I don't actually know much about linux, and I'm trying to learn. That's why I got the raspberry pi actually. Anyway, can someone head me in the right direction?
I already know I need to put it in /etc/init.d/.
You could do this:
IP_ADDR=$(ifconfig eth0 | sed -rn 's/^.*inet addr:(([0-9]+\.){3}[0-9]+).*$/\1/p')
wget -q -O /dev/null http://mywebsite.com/private/CurrentIP.php?send=${IP_ADDR}
...but if your machine is stuck behind NAT, $IP_ADDR won't be your externally-visible address. Might want to use $_SERVER['REMOTE_ADDR'] in your PHP instead of/in addition to this to get the address for your client that your server sees.
Edit: Sounds like you want to be able to find your Raspberry Pi on your local (DHCP-managed) network after reboots. Have you considered using Multicast DNS instead?
How it works in practice: Let's say you've set the hostname of your RasPi to gooseberry. If you've enabled a multicast DNS server on that machine, other computers on the same network segment that can send multicast DNS queries will be able to find it at the domain name gooseberry.local. This is a peer-to-peer protocol and not dependent on gooseberry receiving any specific address via DHCP - so if it reboots and receives a new address, other machines should still be able to find it.
Mac OS X has this enabled out of the box; this can be enabled on most Linux distros (on Debian/Ubuntu you'd install the avahi-daemon and libnss-mdns packages); not sure about Windows, but a quick Google shows encouraging results.
This worked for me (wget part untested, but it finds IP address):
interface="eth0"
ip_addr=$(ifconfig ${interface} | sed -rn 's/^.*inet *([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}).*$/\1/p')
wget -q -O /dev/null http://mywebsite.com/private/CurrentIP.php?send=${ip_addr}
Can't you use:
hostname --ip-address
I'm trying to edit /etc/sysconfig/network-scripts/route-eth0 to make all multicast packets sent to device eth0 on RedHat 6.3, following this guide.
I tried writing like:
224.0.0.0/4 dev eth0
but it never works....
How can I specify multicast routing on this file?
I think you should add route in /etc/sysconfig/static-routes
One more alternative solution to save permanent route is add your route command in following file.
/etc/rc.local
More option to look.
also Enable MC routing in kernel
sysctl -w net.ipv4.conf.all.mc_forwarding=0
Make sure you have MC routing support in kernel. for example.
# cat /boot/config-`uname -r` | grep IP_MROUTE
CONFIG_IP_MROUTE=y
Netstat also tell you whether it enable or not
netstat -g