Create an IP alias for a network interface in OSX
ifconfig en0 inet 192.168.64.25 netmask 255.255.255.0 alias
ifconfig en0 inet 192.168.64.25 netmask 255.255.255.0 alias
Sometimes you need to connect to two different networks from the same physical network card, this is when network interface aliasing comes in handy:
sudo ifconfig eth0:home 192.168.0.1
sudo ifconfig eth0:work 10.0.0.1
You now have two virtual NICs and can access both network segments.
See Network Interface Aliasing in Linux for more information.
Here’s how to find the IP address of a specific network interface that matches a given CIDR:
- hosts: all
gather_facts: false
tasks:
- set_fact:
prod_ip_addr: "{{ item }}"
when: "item | ipaddr('192.168.10.0/24')"
with_items: "{{ ansible_all_ipv4_addresses }}"
- debug: var=prod_ip_addr
This is useful for example when you have a separate management network interface.
It’s almost as easy as trying to explain what the script is doing in plain English.
This works on Linux if “/dev/tcp” is not disabled:
$ cat < /dev/tcp/google.com/80
If the connection is opened successfully the command will wait for input, i.e., nothing will happen. If the port is closed you will get an error.
See:
https://news.ycombinator.com/item?id=3609061
http://tmartiro.blogspot.com/2012/02/udptcp-connection-using-pure-bash.html