every time I connect to my VPN, I should run
sudo ifconfig ppp0 mtu 1300
How could I make it permanent?
I'm using Ubuntu 14.04
You can make your custom script
at this address : /etc/network/if-up.d,
#!/bin/sh
if [ "$IFACE" = "ppp0" ]; then
sudo ifconfig ppp0 mtu 1300
fi
finally make executable and enjoy from your life ...
I've tried to apply Farshad's solution on ubuntu 16, and it wasn't working.
Only small fix was needed there - remove sudo from your script, because everything inside /etc/network/if-up.d/ dir is already run as root user.
#!/bin/sh
if [ "$IFACE" = "ppp0" ]; then
ifconfig ppp0 mtu 1300
fi
Related
How can one obtain MTU range supported by some network device in Linux from bash-script (not directly through netlink API)?
I tried to play with ifconfig and ip link but can't find the solution.
Package iproute2 (since v4.19) parses min/max mtu details and prints it to console when "--details" option is provided by user
ip --details link
ip --details link --name=eth0
ip --details addr
ip --details addr show dev eth0
example of script
#!/bin/bash
for nic in eth0 eth1 eth2; do
min_mtu=`ip --details link show $nic | grep 'minmtu'| sed -r 's/^(.*minmtu) ([0-9]+) (.*)$/\2/'`
max_mtu=`ip --details link show $nic | grep 'maxmtu'| sed -r 's/^(.*maxmtu) ([0-9]+) (.*)$/\2/'`
echo "$nic - min: $min_mtu, max: $max_mtu"
done
output:
eth0 - min: 60, max: 9000
eth1 - min: 68, max: 1770
eth2 - min: 68, max: 1770
Debian 10 already has recent enough version of iproute2 package (v4.20) to display min/max mtu.
Ubuntu 18.04.3 has a kernel which already provides this information to userspace but iproute2 package is not fresh enough(v4.15) to parse kernel's data (and display them to the user).
You can build fresh iproute2 tools yourself in case you have outdated package.
git clone git://git.kernel.org/pub/scm/network/iproute2/iproute2.git
cd iproute2 && ./configure && make && ./ip/ip --details link
Every time I reboot my ubuntu server, it loses it's nameserver setting. I have to run:
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
each time I reboot for it to work properly again.
I tried editing resolv.conf directly and still doesn't work properly.
Any advice?
Edit below file for making effect on every time when you reboot
This is head section of resolve conf which added in resolve.conf
/etc/resolvconf/resolv.conf.d/head
In Ubuntu 18.04 thats working:
Sudo rm /etc/resolv.conf
sudo echo "nameserver xxx.xxx.xxx.xxx" >> /etc/systemd/resolve/resolv.conf
sudo ln -s /etc/systemd/resolve/resolv.conf /etc/resolv.conf
But I think a better option would be to edit the /etc/network/interfaces file and configure the system correctly, including the dns you need, for example:
auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet dhcp
dns-nameservers 8.8.8.8 8.8.4.4
In this example the first two lines define the local interface, do not touch it, the third line says that when the computer boots up the network card enp0s3 simultaneously (you can find out the name of your network card(s) with the command ifconfig -a), the fourth line tells the enp0s3 card to listen to a dhcp server and take the data needed for its network configuration from there, and the last line tells it which dns you want to use.
If you know your network configuration, it will always be the same or you don't have a dhcp server, the file would be something like this:
auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet static
address 10.10.5.67
netmask 255.255.255.0
gateway 10.10.5.1
broadcast 10.10.5.255
dns-nameservers 8.8.8.8 8.8.4.4
Another possibility is to configure the netplan file, the new default mode to manage the network from ubuntu 17.10 Artful. Here you can see more on the subject, particularly I don't like it but I am aware of its power for complex cases.
You can keep settings by editing a base file.
Install resolvconf:
sudo apt-get install resolvconf
Edit /etc/resolvconf/resolv.conf.d/base:
sudo vi /etc/resolvconf/resolv.conf.d/base
Add your nameserver:
nameserver 8.8.8.8
Start resolvconf:
sudo /etc/init.d/resolvconf start
Check that /etc/resolv.conf contains the following line:
nameserver 8.8.8.8
Then try to restart your server and check /etc/resolv.conf again.
That happens because of resolvconf. As the man page states, it allows other programs to change the DNS resolver configuration. Probably, there is a DHCP server on your network that is providing your host its IP address and the DSN servers.
You can change the DHCP configuration or force the first lines of resolv.confas #sahilKataria suggested. Using your command:
echo "nameserver 8.8.8.8" | sudo tee /etc/resolvconf/resolv.conf.d/head
Edit your netplan file. Example:
sudo vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
enp0s31f6:
dhcp4: true # Using DHCP
dhcp4-overrides: # Override DHCP
use-dns: false # Disable DHCP DNS
routes:
- to: x.x.x.x/24
via: x.x.x.x
metric: 100
- to: x.x.x.x/24
via: x.x.x.x
metric: 100
nameservers: # Name Server section
search: [somename.ddns.net] # Set your nameserver search
addresses: [x.x.x.x] # Set your DNS Server
version: 2
When you are done, run:
netplan apply
And make sure that you have this:
$ ls -ltra /etc/resolv.conf
/etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf
If bind is installed on the same machine:
$ cat /etc/hosts
127.0.1.1 somename.ddns.net somename # example
bind-ipaddress somename.ddns.net somename # example
arp ether –i eth0 -s 10.252.108.143 00:24:e8:08:a2:ad
ether:unknow host
what sould I do? please help me
use
sudo arp -t ether -i eth0 -s 10.252.108.143 00:24:e8:08:a2:ad
Trying to figure out how one can use iproute2 to manage static label-switched MPLS routes in Linux kernel 4.1.
I am aware iproute2 support for MPLS might be incomplete right now [2].
Can anyone please shed some light on what iproute2-4.1.1 is currently able to do?
This is what I have found so far:
Documentation/networking/mpls-sysctl.txt
/proc/sys/net/mpls/platform_labels
/proc/sys/net/mpls/conf//input
Load mpls module
sudo modprobe mpls_router
Find sysctl support
sysctl -a --pattern mpls
net.mpls.conf.eth0.input = 0
net.mpls.conf.eth1.input = 0
net.mpls.conf.lo.input = 0
net.mpls.platform_labels = 0
Enable mpls support
sudo sysctl -w net.mpls.conf.eth0.input=1
sudo sysctl -w net.mpls.conf.eth1.input=1
sudo sysctl -w net.mpls.platform_labels=1000
push??? (how to add prefix-to-push action?)
sudo ip route add 1.1.1.1/32 via mpls 100/200/300 dev eth0
swap??? (how to add label-swap action?)
sudo ip -f mpls route add 10 via mpls 100/200/300 dev eth0
pop??? (how to add label-pop action?)
???
show??? (how to display label-switched routes?)
???
Can someone help me out .
Thanks in Advance.
A little bit too late, but hope it helps somebody. You can find them here:
Routing 10.10.10.10/32 to 192.168.1.2 with label 100:
ip route add 10.10.10.10/32 encap mpls 100 via inet 192.168.1.2
Label swapping 100 for 200 and sent to 192.168.2.2:
ip -f mpls route add 100 as 200 via inet 192.168.2.2
Decapsulating label 300 and delivering locally:
ip -f mpls route add 300 dev lo
To show MPLS routes you can do:
ip -f mpls route show
If your iproute2 version doesn't support those commands, you can get it from here:
https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-4.6.0.tar.gz
And then
./configure && make && make install
In a separate question (link below), it was suggested that I obtain the network interface card number and subnet mask from a remote SSH login, rather than prompting the user for it. All I have is the IP address of my remote host. I need to obtain the subnet mask to determine if the remote and local host are on the same subnet, and the interface card number to set up and configure a virtual IP for aliasing purposes.
Could someone suggest how I might be able to parse out the necessary information and return it to my shell script that initiates the remote ssh connection? My target hosts have Linux or AIX as the operating system. I am familiar with the netstat function, but I'm not sure if parsing information from this is valid, or if there is a better way to get what I need that will work for both Linux and AIX operating systems.
Thanks for any help you can provide!
How to return from shell 'read' command passed in expect script?
--UPDATE--
AIX ifconfig -a:
$ ifconfig -a
en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPR
T,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN>
inet 10.105.65.131 netmask 0xffff0000 broadcast 10.105.255.255
tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
lo0: flags=e08084b,c0<UP,BROADCAST,LOOPBACK,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64
BIT,LARGESEND,CHAIN>
inet 127.0.0.1 netmask 0xff000000 broadcast 127.255.255.255
inet6 ::1%1/0
tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1
AIX netstat -rn:
$ netstat -rn
Routing tables
Destination Gateway Flags Refs Use If Exp Groups
Route tree for Protocol Family 2 (Internet):
default 10.105.65.1 UG 31 39412125 en0 - -
10.105.0.0 10.105.65.131 UHSb 0 0 en0 - - =
>
10.105/16 10.105.65.131 U 219 985607244 en0 - -
10.105.65.131 127.0.0.1 UGHS 5 1326738 lo0 - -
10.105.255.255 10.105.65.131 UHSb 3 6926640 en0 - -
127/8 127.0.0.1 U 36 11962928 lo0 - -
Route tree for Protocol Family 24 (Internet v6):
::1%1 ::1%1 UH 1 393270 lo0 - -
I tried route get and that doesn't work on my AIX box to tell me the route. The only thing I can get to work is netstat -rn. I'm not sure if there is another command similar to ip route that would work.
The Linux boxes support both ip and ifconfig.
I am not sure what to do when there are multiple network interface cards, as I do not know which one really should be used when setting up a virtual IP.
The Linux setup is more what I am concerned with, as I will be eventually adding in the AIX support for my software installation script later and can do more research on it then.
For Linux, I might do this something like so (using bash extensions, so invoked using a #!/bin/bash shebang, or piping the script over stdin to an interpreter invoked as ssh "$hostname" bash <<'EOF'):
internet_address=8.8.8.8 # read data for the NIC used to route here
dev_re='dev ([^[:space:]]+)($|[[:space:]])'
read default_route < <(ip -o route get "$internet_address")
[[ $default_route =~ $dev_re ]] && devname=${BASH_REMATCH[1]}
IFS=$'\n' read -r -d '' -a addresses < \
<(netstat -rn |
awk -v dev="$devname" '$8 == dev && ($2 == "0.0.0.0" || $2 == "default") { print $1 }')
# emit this output however you like
printf '%s\n' "$dev_re" "${addresses[#]}"