How do I make my default (or any static) route permanent on Linux (Fedora 9 specifically)? [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 1 year ago.
Improve this question
I've just performed a new installation of the very latest (Fall, 2008) version of Fedora 9 Linux and am perplexed that it never set the default route properly and that even traveling the labyrinthine ways of this OS, there's no obvious way.
Of course, it's clear that one can do it on a one-off basis like this:
route add default gw gw1 metric 0 eth0
or like this:
ip route add to default via 192.168.2.1 protocol static
However, neither of these survives reboot. In reading through /etc/rc.d/init.d/network, it attempts to find data from a file in /etc/sysconfig/static-routes, but that file never existed. So, I tried to create it and populate it with data. The trouble with that is that the script places a dash (minus sign) in an odd spot that I'm not sure how to deal with.
Of course, one can just edit /etc/rc.d/init.d/network, but that would be non-standard. As it is, my only other recourse seems to be editing rc.local, but that doesn't come early enough in the boot sequence to be there for things like, for example, the network time daemon.
I've done my homework - I've read all the man pages, info entries, tried apropos, and I've even done a fair bit of web searching, all to no avail - my next step, sans answer here, will be to sign up to the Fedora mailing lists and ask there! Or, give up and edit the scripts.
So, how is one supposed to do this?

The gateway is normally set in /etc/sysconfig/network-scripts/ifcfg-eth0, not in /etc/sysconfig/network. For example, on my current machine:
/etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=flyboys
NISDOMAIN=ekcineon
/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
HWADDR=00:1d:09:31:3a:cc
NETMASK=255.255.255.0
IPADDR=150.102.65.30
GATEWAY=150.102.65.252
TYPE=Ethernet
Note that I set HWADDR because I have two ethernet cards and I want to make sure the right one is assigned to eth0. The configuration for the second card is in /etc/sysconfig/network-scripts/ifcfg-eth1

just edit the /etc/sysconfig/network-scripts/route-ethXX
and write inside: default via ip_address dev device , replace ip_address with your gateway ip and device with the name of the right eth device. but for the Device option its ... optional, set it in the case of multiple eth devices.
Works even in case of network restart, the route directive in rc.local works at boot only.

I have not used recent versions of Fedora, but it was often set as a GATEWAY variable in /etc/sysconfig/network.
Of course, if you just wanted it to work, you could just put the commands in /etc/rc.local to be executed when the boot sequence completes.

You can use nmcli if available, e.i.
# nmcli con show
NAME UUID TYPE DEVICE
System eth0 xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ethernet eth0
ens33 xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ethernet --
# nmcli con edit "System eth0"
nmcli> goto ipv4
You may edit the following properties: method, dns, dns-search, dns-options, dns-priority, addresses, gateway, routes, route-metric, route-table, routing-rules, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-timeout, dhcp-send-hostname, dhcp-hostname, dhcp-fqdn, never-default, may-fail, dad-timeout
nmcli ipv4>
nmcli ipv4> print
['ipv4' setting values]
ipv4.method: manual
ipv4.dns: --
ipv4.dns-search: --
ipv4.dns-options: --
ipv4.dns-priority: 0
ipv4.addresses: 10.10.10.1/26
ipv4.gateway: 10.10.10.129
ipv4.routes: --
ipv4.route-metric: -1
ipv4.route-table: 0 (unspec)
ipv4.routing-rules: --
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0 (default)
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
nmcli ipv4>
nmcli ipv4> set routes 192.168.122.0/24 10.10.10.1
nmcli ipv4> verify
Verify setting 'ipv4': OK
nmcli ipv4> save
nmcli ipv4> quit
#nmcli con up "System eth0"
And it should create file /etc/sysconfig/network-scripts/routes- with proper parameters, e.g.
ADDRESS0=192.0.2.0
NETMASK0=255.255.255.0
GATEWAY0=198.51.100.1

Haven't seen Fedora. But shouldn't there be some GUI for this kind of thing? If you have Gnome try running gnome-network-preferences

Here it is for RHEL, as it is slightly different:
Identify the interface by using ifconfig
sudo vi /etc/sysconfig/network-scripts/route-ethXX
add the routes as per syntax below, where /xx represents subnet mask
host: 172.30.xxx.xxx via 172.30.xxx.xxx
network: 172.30.xxx.xxx/xx via 172.30.xxx.xxx
Default gateway: 0.0.0.0 via xxx.xxx.xxx.xxx</li>
Save the file.
sudo /etc/init.d/network restart (Warning: if you forget to set
correct routes for the management interface (if applicable) you may lose
connectivity to the server)

Related

Explanation regarding `showmount -e` needed - what does "#" mean?

As stated in the title: What does the #... in the output below mean? I don't think they are hostnames, because I think the #-sign is reserved for mailing. Normally there stands a IP-subnet or simply an IP-address - but nothing is the case here. I also know I can put hostnames in there, but I don't think I could put such #... into the hosts file to restrict the access to only some IPs... Sooo, what is this?
glaforge#enterprise: showmount -e [REMOVED]
Export list for [REMOVED]:
[REMOVED] *
[REMOVED] #somenamea,#somenameb
In the list of exports shown by showmount -e any names with an # are netgroups, not individual hosts.
A netgroup is a list of hosts. They're typically defined in /etc/netgroup on the NFS server (but could also be in NIS, LDAP, etc. depending on how /etc/nsswitch.conf is configured).
Using netgroups to define your exports saves a lot of typing compared to exporting to each host separately. (I find that it reduces the chances of making typos. Or if I do make a typo in one of my exports, I'll find it faster as it'll affect all the machines in the netgroup rather than just one machine.)
Example
On my NFS server I could have the following netgroups defined in /net/netgroup:
nuts (walnut,,) (almond,,) (pistachio,,) (hazelnut,,)
flowers (rose,,) (tulip,,) (iris,,)
Each entry in a netgroup is defined as a tuple of (hostname, user, NIS domain) but NFS only cares about the hostname so just leave the other parts blank. The NIS domain is not the same thing as a DNS domain. If you need to specify a full DNS name, e.g., foo.example.com, put it all in the host part: (foo.example.com,,)
And then my exports file could look like this:
/vol/home #nuts(rw) #flowers(rw)
/vol/web #nuts(rw)
/vol/dns #nuts(ro) almond(rw)
Now the hosts in the flowers netgroup can mount home read-write but can't access web or dns. The host almond has read-write access to everything, but the rest of the machines in the nuts netgroup only have read-only access to dns.
If I were to run showmount -e it would look something like this:
% showmount -e
Export list for example.com:
/vol/home #nuts,#flowers
/vol/web #nuts
/vol/dns #nuts,almond

What is the syntax of DISPLAY environment variable?

I'm writing program in x86-64 assembly for linux that will create X11 window using only system calls invoked with syscall instruction. Based on the content of the DISPLAY environment variable I have to create either tcp or unix socket. In linux manual "man 7 X" it is written that :
The hostname part of the display name should be the empty string. For example: :0, :1, and :0.1. The most efficient local transport will be chosen.
However I compiled C code example from https://en.wikibooks.org/wiki/X_Window_Programming/XCB and ran compiled executable in GDB with changed DISPLAY environment variable. When I change DISPLAY environment variable from DISPLAY=:0 to DISPLAY=unix:0 or DISPLAY=unix/:0 or DISPLAY=unix/abc:0 window is still created. Is linux manual wrong and what is real syntax of DISPLAY environment variable?
Short Answer: X11 can run over multiple transport. The comment is related to 'local' connection.
Long Answer:
The quote that you include refers to 'local' connection. The X11 system can run over few tarnsport layers. On my system:
local
The hostname part of the display name should be the empty string. For example: :0, :1, and :0.1. The most effi‐
cient local transport will be chosen.
TCPIP
The hostname part of the display name should be the server machine's hostname or IP address. Full Internet names,
abbreviated names, IPv4 addresses, and IPv6 addresses are all allowed. For example: x.org:0, expo:0, [::1]:0,
198.112.45.11:0, bigmachine:1, and hydra:0.1.
Also, many systems support running over unix sockets, which had (at least in the past) more efficient that TCP connections.

Persistant name in usb device which open several connections || connect USB to specific port [duplicate]

This question already has an answer here:
Change default names for USB virtual serial ports in Linux
(1 answer)
Closed 5 years ago.
I am trying to add a persistent name to a USB device connection to be able to connect to it by writing /dev/multitech instead of /devttyACMx. I have been able to do so with other devices by adding an udev rule, for example:
SUBSYSTEM=="tty", ATTRS{idVendor}=="1bc7", ATTRS{idProduct}=="0021",ATTRS{serial}=="356136967675473", SYMLINK+="multitech"
The problem is that this device open 6 connections, from ttyACM0 to ttyACM5 (if nothing else connected) but to use it you have to use the ttyACM0 (meaning the first connection) but if you write:
$ ls -l /dev/multitech
you may get whatever connection it has open, maybe ttyACM0 or maybe ttyACM3... the thing is that this is useless for me, since it sometimes works and sometimes it does not. Is there anything I can do about this?
Thanks a lot!!
normally each connection the device establishes has its own interface or alternate setting in USB tree structure. in udev rules you can use several other attributes (all you can display using udevadm info --attribute-walk http://www.beyondlogic.org/usbnutshell/usb5.shtml#InterfaceDescriptors )
run an attribute walk with udevadm info --attribute-walk + /sys/class/... or /dev/... path for your device to see the identifiers of the several usb interfaces it has in its usb structure and try to include them in the udev rule, i.e. using the following attributes:
ATTRS{bAlternateSetting}=="..."
ATTRS{bInterfaceClass}=="..."
ATTRS{bInterfaceNumber}=="..."
ATTRS{bInterfaceProtocol}=="..."
ATTRS{bInterfaceSubClass}=="..."
try to assign a specific /dev/ttyACMx for any interface the device has in its usb structure and try to assign the top-level interface in the usb structure to /dev/ttyACM0 ...
http://weininger.net/how-to-write-udev-rules-for-usb-devices.html
Change default names for USB virtual serial ports in Linux
This post was the solution to my troubles, instead of using the /devttyACMx
y changed to used the names in /dev/serial/by-id/
up until now it has worked fine, if it stops doing it I will post it

Automate Bluetooth Pairing/Trusting in Bluez5

I've been working on making my RPi 2 function like a car bluetooth receiver and all is well, except I have no idea how I could automate the pairing of bluetooth devices in Bluez5. In the past I would've used the bluetooth agent and a simple script, but that seems to have gone out the window with the move from 4 -> 5. The nature of the setup means I have no kb/mouse on the RPi once its in the car, so it needs to be a fully automated setup where anyone can scan for the RPi, and if the probably hard-coded PIN is correct, the trusting of the device needs to be automatically done, no cli input.
I've searched all over the web but everyone seems to say that using bluetoothctl works for them, but in this particular setup where I'd like to be able to have friends pair their own phones, having to trust devices with the RPi out of the car isn't ideal.
I'm not sure why you say using a simple script is not possible with bluez5. I think you can do it. Below is one example how.
Download the bluez5 source and edit test/simple-agent. Comment out the lines of code as shown below:
def RequestAuthorization(self, device):
print("RequestAuthorization (%s)" % (device))
#auth = ask("Authorize? (yes/no): ")
#if (auth == "yes"):
return
#raise Rejected("Pairing rejected")
What that does it remove the prompt for authorisation and always accepts the pairing request.
Can now start the simple-agent with the NoInputNoOutput capability so that it uses simple pairing and will go through the above code path:
./simple-agent -c NoInputNoOutput
After that you should be able to pair with the RPi without any user prompt or PIN.
Note that this is just one example of what you can do. If say you wanted to have a hard coded PIN instead of simple pairing then edit the appropriate section of the same simple-agent code to do that. I'll leave that as an exercise for you.
I already had bluez-5.43 installed. This is how to automate the pairing process on a raspberry pi.
(1) First test a line like this out to make sure bluetooth agent works:
bluez-5.43/test/simple-agent -c NoInputNoOutput
(2) To automate pairing, put this code into a shell file (I named mine pairbot.sh):
if [ "$(id -un)" != "pi" ]; then
exec sudo -u pi $0 "$#"
fi
export XAUTHORITY=/home/pi/.Xauthority
export DISPLAY=:0
lxterminal --command="/bin/bash -c '/home/pi/bluez-5.43/test/simple-agent -c NoInputNoOutput &; read'"
(3) Go to crontab:
sudo cronetab -e
(4) At the bottom add:
#reboot sleep 20 && /home/pi/pairbot.sh > /home/pi/blelog.txt 2>&1
(5) Reboot and test if it works.
My recommendation for others facing the same issue would be to look into your bluez folder (or if you don't have one install the latest version of bluez) and search for the folder that says "test" for "simple agent" to locate the file path. From here, you should be able to construct the command line shown above (1). Hopefully it will work for you too.

test if hostname exists from command line without ping

we have a script that needs to take action on a finite list of hosts. but every time we add or remove a host to the /etc/hosts file, we end up having to update this script.
basically, say my hosts file looks like:
192.168.100.1 hostip_1
192.168.100.2 hostip_2
192.168.100.10 hostip_3
192.168.100.20 hostip_5
and my script (bash) does something like:
callmyfunction hostip_1
callmyfunction hostip_2
callmyfunction hostip_3
callmyfunction hostip_5
if i want to add hostip_4 to the list of hosts, i now have to go in and edit my script and add it to the list. while it's a small edit, it is still a step that can be forgotten in the process (especially if someone new to the system comes in).
is there a way i can test to see if 'hostip_1' is a valid hostname within the system (without pinging the host or grepping the /etc/hosts file)? we may use multiple hosts files, and different configurations may have different filenames, so i can't rely on trying to grep a single file. i need the system to do that work for me.
any clues?
first, my statement about things not being in the hosts file is wrong. that is exactly where they are. dumb on my part.
but the answer is:
getent hosts
that will get it to print everything out, and i can do a lookup from there.
As you are populating the /etc/hosts file, I am assuming that you are not using DNS. So below solution wont fit your use case. But it will still get you some pointers.
In a working DNS environment, you can check the host name to its corresponding IP with below command
# host host_name
This is will give the IP address of the host. In case the host name does not exists, then it will give you corresponding host not found message.
You can parse the output of above command and can deduce whether a give host name exists.
might not be in your /etc/hosts file... better search for the name and see if an ip can be found:
(($(dig +noall +answer google.de |wc -c)>0)) && echo exists
this is bash, can be adaptet to pretty much everything.
dig +noall +answer google.de
returns the ips if found. If empty, that name cannot be used in the computer running this code.
If all the targets are on the same subnet (same network), use arping, it will check that hosts are available using ARP.

Resources