Created
December 30, 2020 06:41
-
-
Save knrt10/fa0aea379156e49245a7d2b61ead3548 to your computer and use it in GitHub Desktop.
personal notes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # change all occurances in git repository | |
| git grep -l 'original_text' | xargs sed -i '' 's/original_text/new_text/g' | |
| # For commenting multiple lines in vim: | |
| :66,70s/^/# | |
| # For uncommenting multiple lines in vim: | |
| :66,70s/^#/ | |
| # What files changed for 1 commit in git repo | |
| git whatchanged -1 --format=oneline | |
| # About garbage collection | |
| https://www.reddit.com/r/golang/comments/7tlw83/when_does_garbage_collection_occurs/ | |
| # Rust alternatives | |
| - https://github.com/sharkdp/bat replacing cat | |
| - https://github.com/sharkdp/fd replacing find | |
| - https://github.com/sharkdp/hyperfine for benchmarking | |
| - https://github.com/BurntSushi/ripgrep replacing grep | |
| - https://github.com/ogham/exa replacing ls | |
| # Ip tables debugging | |
| https://backreference.org/2010/06/11/iptables-debugging/ | |
| # Setting alias and autocompletion and setting namespace for context in kubernetes | |
| echo 'alias kc="kubectl"' >> ~/.bashrc && source ~/.bashrc && echo "source <(kubectl completion bash)" >> ~/.bashrc && complete -F __start_kubectl kc | |
| kc config set-context $(kc config current-context) --namespace=default | |
| # Experimenting with Net namespace | |
| ip netns add red | |
| ip netns add blue | |
| ip link add veth-red type veth peer name veth-red-br | |
| ip link add veth-blue type veth peer name veth-blue-br | |
| ip link add v-net-0 type bridge | |
| ip link set veth-red netns red | |
| ip link set veth-blue netns blue | |
| ip link set veth-red-br master v-net-0 | |
| ip link set veth-blue-br master v-net-0 | |
| ip -n blue link set lo up | |
| ip -n red link set lo up | |
| ip -n red link set veth-red up | |
| ip -n blue link set veth-blue up | |
| ip link set v-net-0 up# My host IP is 147.75.100.73 | |
| ip -n red addr add 147.75.100.1/24 dev veth-red | |
| ip -n blue addr add 147.75.100.2/24 dev veth-blue | |
| ip addr add 147.75.100.3/24 dev v-net-0# setup gateway | |
| ip netns exec red ip route add default via 147.75.100.3 | |
| ip netns exec blue ip route add default via 147.75.100.3 | |
| # to ping outside world | |
| echo 1 > /proc/sys/net/ipv4/ip_forward | |
| iptables -t nat -A POSTROUTING -s 147.75.100.3/24 -j MASQUERADE | |
| # Finally | |
| ip netns exec blue ping 8.8.8.8 | |
| # Result of above experimentation: | |
| If you want to extend your home L2 network, the bridge should not have an IP address | |
| (it's just a bridge and does the forwarding based on Ethernet headers), | |
| in that case you should configure the default gateway on the namespaces as it's configured | |
| in your host (probably the IP address of the "box" that the ISP gives you). In this case the masquerading rule is not needed. | |
| If you want to create a different subnet, they you should configure IP addresses for the veth interfaces | |
| that don't overlap with your home network, the gateway on the namespaces would be an address in the host | |
| and you'll need masquerading too. | |
| Btw, having a different subnet is easier to configure. | |
| Just the same you did but setting putting the veth in a non-overlapping network with your home network. | |
| If you want to extend the L2, IIRC you'd need to connect also the physical interface of your machine to | |
| the bridge and if you still want the host to connect to the internet you'll have to create another veth pair, | |
| one end connected to the bridge and the other end on the host (and assign an IP address to it). | |
| It'll give host access to the internet. | |
| # Dev hints | |
| https://devhints.io/ | |
| # rerun the last command with sudo (and shout at your terminal while at it). | |
| sudo !! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment