wrectos@WRECK:~$ echo $TERM rxvt-unicode wrectos@WRECK:~$ tmux open terminal failed: missing or unsuitable terminal: rxvt-unicode wrectos@WRECK:~$ echo 'TERM=xterm' >> .bashrc wrectos@WRECK:~$ source .bashrc wrectos@WRECK:~$ echo $TERM xterm wrectos@WRECK:~$ tmux wrectos@WRECK:~$
Pathological adventures in networking, programming, and life -- narrated by a survivor of the learn-by-doing tribe.
Tuesday, July 26, 2016
Using TMUX with URXVT
Thursday, June 28, 2012
Intro to File Permissions
Intro to File Permissions
Ever want to know who has access to your files and what they're allowed to do to those files? Turns out there are permissions that do exactly those two things.
Let's start by listing out the folder contents in long format with ls -l (shortcut: ll)
alchemist@BogWarfs:/opt/test$ ll total 12 -rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault -rw-r----- 1 deltys elves 113 Jun 28 22:55 elvenVault -rw-r----- 1 herpderp goblins 109 Jun 28 22:56 goblinVault alchemist@BogWarfs:/opt/test$ cat dwarvenVault cat: dwarvenVault: Permission denied
Breakdown
Starting from right-to-left.
Filename
You can bequeath names in the common tongue.
-rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault
File name.
Modify Time
Timestamp. If you touch it, it will change. There are different timestamps too but that's a topic for another day.
-rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault
File Size
The file size here is 100 bytes. Whoopie.
-rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault
Group Name
This file belongs to the group, 'dwarves'. A file can have at most one group.
-rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault
Owner Name
This file belongs to the user, 'organdr'. A file can have at most one owner.
-rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault
Links
There is one link to the file. Topic for another day.
-rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault
Permissions
This is actually a multi-part permissions ACL - Access Control List.
rw-r----- 1 organdr dwarves 100 Jun 26 22:26 dwarvenVault
This row of dashes and letters has all sorts of meaning. Let's go through what each of the letters stand for. The meanings of these words are lost to mankind.
- d - directory
- r - read
- w - write
- x - execute
There are actually 4 groupings of permissions here.
- Directory (in this case, off)
rw- Owner Permissions (organdr)
r-- Group Permissions (dwarves)
--- Global Permissions (everyone else)
From this ACL we can see that Organdr can read/write to the dwarvenVault, Dwarves can read from the Vault, and everyone else isn't allowed to do anything to dwarvenVault.
That's enough for one sitting, we'll talk about changing permissions in the next entry.
Tuesday, June 26, 2012
Linux - Intro to sed - Text replacement
Linux - Inplace Text Replacement
Here's one way you can do a text replacement in Linux. This is useful for mass-editing files like html, source code, or whatever text file you use.
Example 1: Turn Lead into Gold
Here are the contents of a file,
alchemist@BogWarfs:/opt/test$ cat dwarvenVault Inventory ------------------- 5 x Lead bricks 10 x Lead bracelets 20 x Lead rings 42 x Lead swords alchemist@BogWarfs:/opt/test$
Let's do alchemy!
alchemist@BogWarfs:/opt/test$ sed 's/Lead/Gold/g' dwarvenVault Inventory ------------------- 5 x Gold bricks 10 x Gold bracelets 20 x Gold rings 42 x Gold swords alchemist@BogWarfs:/opt/test$ cat dwarvenVault Inventory ------------------- 5 x Lead bricks 10 x Lead bracelets 20 x Lead rings 42 x Lead swords alchemist@BogWarfs:/opt/test$
Aw poop, we have the change, but it didn't stick in the file. Ho hum.
alchemist@BogWarfs:/opt/test$ sed -i 's/Lead/Gold/g' dwarvenVault alchemist@BogWarfs:/opt/test$ cat dwarvenVault Inventory ------------------- 5 x Gold bricks 10 x Gold bracelets 20 x Gold rings 42 x Gold swords alchemist@BogWarfs:/opt/test$
Example 2: Multiple files
You can also use a regex or some other mechanism to change many files at once.
alchemist@BogWarfs:/opt/test/$ ls dwarvenVault elvenVault goblinVault alchemist@BogWarfs:/opt/test/$ cat * Inventory ------------------- 5 x Lead bricks 10 x Lead bracelets 20 x Lead rings 42 x Lead swords Inventory -------------------- 24 x Lead bricks 300 x Lead bracelets 50 x Lead rings 15 x Lead swords Inventory -------------------- 191 x Lead bricks 3 x Lead bracelets 1 x Lead rings 26 x Lead swords alchemist@BogWarfs:/opt/test/$ sed -i 's/Lead/Gold/g' *Vault alchemist@BogWarfs:/opt/test/$ cat * Inventory ------------------- 5 x Gold bricks 10 x Gold bracelets 20 x Gold rings 42 x Gold swords Inventory -------------------- 24 x Gold bricks 300 x Gold bracelets 50 x Gold rings 15 x Gold swords Inventory -------------------- 191 x Gold bricks 3 x Gold bracelets 1 x Gold rings 26 x Gold swords alchemist@BogWarfs:/opt/test/$
Yer a wizard 'Arry
Monday, June 25, 2012
Remote DHCP
Remote DHCP on Cisco IOS
Case 1: Single Subnet
Devices
- Spider Station Router: 10.111.0.1/24
- Spider Station Switch: 10.111.0.2/24
- HQ Router: 10.200.0.1/24
- HQ DHCP Server: 10.200.0.2/24
Spider Router
hostname Spider-RTR ! interface FastEthernet 0/0 ip address 10.111.0.1 255.255.255.0 ip helper-address 10.200.0.2
Ta-da! That's it.
Simply add an IP helper to whatever fancy interface you're using. Port-channel, Ether-channel, Vlan, Multilink, BVI, or some other menacing interface/sub-interface.
Fail Warning: If an interface has sub-interfaces, apply it to the sub-interface. Helpers will not be inherited from the parent interface.
Fail Warning: The above also applies to logical interfaces. Even though Fa0/0 and Fa0/1 may be in Port-Channel 1, the helper must be applied to the port channel, not the physical interfaces.
When a client broadcasts a DHCPDiscover, Spider-RTR relays it using that interface's primary interface. (Putting an IP helper-address on a trunk port will make your router/L3 switch feel silly.)
Case 2: With Redundancy
Using multiple remote DHCP servers.
Devices
- Spider Spider Station Router: 10.222.0.1/24
ReinforcedSpider Router
hostname SpiderSpider-RTR ! interface GigabitEthernet 0/3 ip address 10.222.0.1 255.255.255.0 ip helper-address 10.200.0.100 ip helper-address 10.200.0.101
In this case, the DHCPDiscover is sent to both DHCP servers. It's OK though, because the client will only DHCPRequest one offer. Unless it's Eve and she's trying to consume all of my precious IPs...but that's another issue.
Case 3: With Secondary IPs
Sometimes an office's network needs grow and you have to temporarily (ha!) put a second subnet at the branch.
Since the helper only sources the primary interface by default, we'll need an extra command.
ip dhcp smart-relay
If the router doesn't detect a DHCPOffer, it will then relay a DHCPDiscover with a different giaddr in the DHCP packet. Layman's terms: it will try the secondary addresses.
Devices
- Hungry Caterpillar Router (new subnet): 10.33.1.1/24
- Hungry Caterpillar Router (old subnet): 10.33.0.1/25
Hungry Caterpillar Router
hostname HungryCaterpillar-RTR ! ip dhcp smart-relay ! interface FastEthernet 1/1 ip address 10.33.0.1 255.255.255.128 secondary ip address 10.33.1.1 255.255.255.0 ip helper-address 10.200.0.100 ip helper-address 10.200.0.101Well that's it from me tonight.
Sunday, June 24, 2012
Redundant DHCP
Adventures in Networking - DHCP - Part 2: Redundancy
- Hear a DHCP discover.
- Reserve an available IP from a DHCP pool, recording the MAC of the requester.
- Offer the IP.
- Acknowledge that the IP was accepted.
Simple Setup - Single DHCP Server
This DHCP server will hand out IPs for the 10.0.0.0/24 network. It will use Google for DNS (8.8.8.8). We exclude the range 10.0.0.1 - 10.0.0.10 for our network equipment.Router 1
Router(config)# ip dhcp excluded-addresses 10.0.0.1 10.0.0.10 Router(config)# ip dhcp pool david Router(dhcp-config)# network 10.0.0.0 255.255.255.0 Router(dhcp-config)# domain-name example.davidisbad.com Router(dhcp-config)# dns-server 8.8.8.8 Router(dhcp-config)# default-router 10.0.0.1
Redundancy Setup - Two DHCP Servers
Router 1 serves 10.0.0.11 - 10.0.0.127.Router 2 serves 10.0.0.128 - 10.0.0.254.
Router 1
Router1(config)# ip dhcp excluded-addresses 10.0.0.1 10.0.0.10 Router1(config)# ip dhcp excluded-addresses 10.0.0.128 10.0.0.255 Router1(config)# ip dhcp pool david Router1(dhcp-config)# network 10.0.0.0 255.255.255.0 Router1(dhcp-config)# domain-name example.davidisbad.com Router1(dhcp-config)# dns-server 8.8.8.8 Router1(dhcp-config)# default-router 10.0.0.1
Router 2
Router2(config)# ip dhcp excluded-addresses 10.0.0.1 10.0.0.127 Router2(config)# ip dhcp pool david Router2(dhcp-config)# network 10.0.0.0 255.255.255.0 Router2(dhcp-config)# domain-name example.davidisbad.com Router2(dhcp-config)# dns-server 8.8.8.8 Router2(dhcp-config)# default-router 10.0.0.1
Saturday, June 23, 2012
Intro to DHCP
Adventures in Networking - DHCP
Scene 1: Local DHCP Server
- #3: Default Gateway (Router's address)
- #1: Subnet Mask (The boundaries of the subnet)
- #15: Domain Name (Network's name)
- #6: Domain Name Server (Server that knows all the names.)