Changes between Version 34 and Version 35 of Internal/OpenFlow/miscUnix


Ignore:
Timestamp:
May 20, 2013, 9:06:54 PM (8 years ago)
Author:
akoshibe
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Internal/OpenFlow/miscUnix

    v34 v35  
    88 * `extundelete` - Linux file system recovery
    99 * `cdrecord` - burning bootable ISO's
     10 * process I/O redirection (`gdb`)
     11 * merging pdfs (`gs`)
    1012[#dev Development-related] Tools and workarounds
    11  * process I/O redirection (`gdb`)
    1213 * fixing garbled text (`gcc`)
    1314 * `git` server (bare repo) setup
    1415 * various `git` commands
    1516 * importing non-Eclipse projects to Eclipse
     17 * FreeBSD, mininet (`mn`), and `qemu`
    1618[#net Network] Various networking-related things.
    1719 * Disabling SSH timeout
     
    2022  * with `pf` (*BSD)
    2123 * Wireless with wpa_supplicant 
    22  * FreeBSD `ifconfig` shinaniganries.
    23  * FreeBSD, mininet (`mn`), and `qemu`
     24 * FreeBSD `ifconfig` shinaniganries. 
    2425[#print Quick Printing] Printing under *nix, relatively quickly
    2526 * CUPS
     
    156157you can confirm this with `tail -f` (or the fact that your program has stopped outputting to terminal).
    157158
     159== Merging PDFs. ==
     160This is a long one-liner with Ghostscript (`gs`), a tool that comes with the Ubuntu base install (even server). [[BR]]
     161reference (which references other tools for this purpose) : http://www.linux.com/news/software/applications/8229-putting-together-pdf-files
     162
     163{{{
     164gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
     165}}}
     166
    158167== Fixing garbled gcc and man page output. ==
    159168On some machines, `gcc` and man pages might produce garbled text. This is usually caused by xterm not supporting UTF-8, or from mismatch in locale information if the garbling is happening when you are working on a remote machine. In either case (for people working with US English), setting LANG to `en_US` or `C` fixes things:
     
    214223}}}
    215224
    216 == Miscellaneous Git ops. ==
     225=== Miscellaneous Git ops. ===
    217226 * deleting branches: local - `git branch -D [branchname]` remote - `git push origin :[branchname]` (note the colon prepended to branch name)
    218227 * "rewinding" to a previous commit: `git rebase -i [hash ID]^^` (note the two carets)
    219228 * undoing a rebase: `git reset --hard [tag]`, where [tag] is the "HEAD@{n}" key for the commit from `git reflog`
    220229 * cloning into a renamed directory, from another user's repo, with ssh: `git clone ssh+git://user@repolocation/repo.git [newname]` - the cloned repo will be named [newname] 
    221 
    222 ----
    223 = Networking-related odds and ends = #net
    224 Various non-experimental network setups, usually done for convenience.
    225 == Disabling SSH timeout ==
    226 source: http://docs.oseems.com/application/ssh/disable-timeout
    227 
    228 You can essentially prevent SSH from timing out after a long idle period by adding the following to /etc/ssh/ssh_config :
    229 {{{
    230 ServerAliveInterval 100
    231 }}}
    232 
    233 The above will make the client send a keepalive signal once every 100 seconds. Alternatively, you can modify server-side configs by adding the following to /etc/ssh/sshd_config :
    234 {{{
    235 ClientAliveInterval 30
    236 TCPKeepAlive yes
    237 ClientAliveCountMax 99999
    238 }}} 
    239 
    240 And restarting sshd:
    241 {{{
    242 /etc/init.d/ssh restart
    243 }}}
    244 
    245 
    246 == NAT boxes. ==
    247 NAT boxes are handy if you want to build a gateway. First and foremost, you need to enable IP packet forwarding on your to-be-NAT box. [[BR]]
    248 On Linux, the command
    249 {{{
    250 sudo sysctl -e net.ipv4.ip_forward=1
    251 }}}
    252 at the shell enables it. For persistence, add the following line to /etc/default/ufw: 
    253 {{{
    254 net.ipv4.ip_forward=1
    255 }}}
    256 
    257 [[BR]]
    258 Similarly for FreeBSD (assuming you have `sudo` installed),
    259 {{{
    260 sudo sysctl net.inet.ip.forwarding=1
    261 }}}
    262 enables it, and the following line in /etc/sysctl.conf makes it persistent:
    263 {{{
    264 net.inet.ip.forwarding=1
    265 }}}
    266 
    267 === with `ufw` ===
    268 source: https://nowhere.dk/articles/tip_nat_with_ubuntus_ufw_firewall
    269 
    270 `ufw` is your standard Linux firewall, and comes with Ubuntu server edition. Turning a multi-interface Linux box into a router is a matter of the following steps:
    271  1. configure IP forwarding
    272 edit /etc/default/ufw :
    273 {{{
    274 DEFAULT_FORWARD_POLICY="ACCEPT"
    275 }}}
    276  2. set up IP masquerading in `ufw`   
    277 edit /etc/ufw/before.rules, just after the header :
    278 {{{
    279 # nat Table rules
    280  *nat
    281  :POSTROUTING ACCEPT [0:0]
    282 
    283  # Forward traffic through ppp0 - Change to match you out-interface
    284  -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE
    285 
    286  # don't delete the 'COMMIT' line or these nat table rules won't
    287  # be processed
    288  COMMIT
    289 }}}
    290 The address block after -s should match the address block behind the NAT firewall.
    291 
    292  3. restart ufw:
    293 {{{
    294 sudo ufw disable && sudo ufw enable
    295 }}}
    296 
    297 === with `pf` ===
    298 `pf` is the OpenBSD packet filter, a piece of software intended for heavy-duty packet filtering/firewalls and comes with some Berkeley UNIX derivatives. 
    299 Assuming you have IP forwarding enabled, the following configuration in /etc/pf.conf should give you a NAT firewall:
    300 {{{
    301 ext_if="bge0"
    302 int_if="em0"
    303 external_addr="192.168.203.155"
    304 internal_net="192.168.1.0/24"
    305 nat on $ext_if from $internal_net to any -> ($ext_if)
    306 pass in all
    307 pass out all
    308 }}}
    309 `ext_if` is the interface facing the external network, and `int_if` is the interface connected to your NATed net.
    310 Once saved, start `pf`:
    311 {{{
    312 sudo pfctl -e -f /etc/pf.conf
    313 }}}
    314 If it throws errors, make sure that the kernel module (pf.ko or something similar) is loaded.
    315 
    316 == FreeBSD `ifconfig` shinanigans. ==
    317 FreeBSD's `ifconfig` combines the features of `ifconfig` and `iwconfig` in Linux (and probably more). For example, you can get a list of AP's, you can do:
    318 {{{
    319 $ ifconfig wlan0 list scan
    320 SSID/MESH ID    BSSID              CHAN RATE   S:N     INT CAPS
    321 kitchen         08:86:3b:a0:20:f2    6   54M   8:0    100 EP   HTCAP WPA RSN WME WPS
    322 WINMAIN         c4:7d:4f:37:2d:f0    6   54M  15:0    102 ES   HTCAP WME
    323 front.door      08:86:3b:d7:f4:6c    6   54M   5:0    100 EP   RSN HTCAP WME WPS
    324 }}}
    325 And so on.
    326 
    327 Another thing that you can do (unintentionally or otherwise) is to assign multiple network addresses to a single interface. The `add` keyword lets you do this intentionally:
    328 {{{
    329 $ sudo ifconfig wlan0 inet 192.168.206.1 add
    330 $ ifconfig wlan0
    331 wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
    332         ether 00:1c:bf:9a:61:c7
    333         inet 192.168.206.120 netmask 0xffffff00 broadcast 192.168.206.255
    334         inet 192.168.206.1 netmask 0xffffff00 broadcast 192.168.206.255
    335         nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
    336         media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11g
    337         status: associated
    338         ssid WINMAIN channel 6 (2437 MHz 11g) bssid c4:7d:4f:37:2d:f0
    339         country US authmode OPEN privacy OFF txpower 0 bmiss 7 scanvalid 60
    340         protmode CTS bintval 102
    341 }}}
    342 On wired interfaces, assigning addresses with `ifconfig [iface] inet [address]` will have the same effect, which may not be what you want, especially when you expect the old address to just be replaced by your new one^2^. In this case, you can remove the unwanted address with `-alias`:
    343 {{{
    344 $ sudo ifconfig wlan0 inet 192.168.206.1 -alias
    345 $ ifconfig wlan0
    346 wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
    347         ether 00:1c:bf:9a:61:c7
    348         inet 192.168.206.120 netmask 0xffffff00 broadcast 192.168.206.255
    349         nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
    350         media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11g
    351         status: associated
    352         ssid WINMAIN channel 6 (2437 MHz 11g) bssid c4:7d:4f:37:2d:f0
    353         country US authmode OPEN privacy OFF txpower 0 bmiss 7 scanvalid 60
    354         protmode CTS bintval 102
    355 }}}
    356 
    357 Otherwise, this feature is pretty handy for quickly adding a IP interface to an interface for, say (as a silly example), creating a carted-off piece of network for a host you don't want to put on the main network, but you still need to access.   
    358230
    359231== FreeBSD , mininet, and `qemu/kvm`.==
     
    423295
    424296You should be able to reach the VM from the network now/vice versa.
     297----
     298= Networking-related odds and ends = #net
     299Various non-experimental network setups, usually done for convenience.
     300== Disabling SSH timeout ==
     301source: http://docs.oseems.com/application/ssh/disable-timeout
     302
     303You can essentially prevent SSH from timing out after a long idle period by adding the following to /etc/ssh/ssh_config :
     304{{{
     305ServerAliveInterval 100
     306}}}
     307
     308The above will make the client send a keepalive signal once every 100 seconds. Alternatively, you can modify server-side configs by adding the following to /etc/ssh/sshd_config :
     309{{{
     310ClientAliveInterval 30
     311TCPKeepAlive yes
     312ClientAliveCountMax 99999
     313}}} 
     314
     315And restarting sshd:
     316{{{
     317/etc/init.d/ssh restart
     318}}}
     319
     320
     321== NAT boxes. ==
     322NAT boxes are handy if you want to build a gateway. First and foremost, you need to enable IP packet forwarding on your to-be-NAT box. [[BR]]
     323On Linux, the command
     324{{{
     325sudo sysctl -e net.ipv4.ip_forward=1
     326}}}
     327at the shell enables it. For persistence, add the following line to /etc/default/ufw: 
     328{{{
     329net.ipv4.ip_forward=1
     330}}}
     331
     332[[BR]]
     333Similarly for FreeBSD (assuming you have `sudo` installed),
     334{{{
     335sudo sysctl net.inet.ip.forwarding=1
     336}}}
     337enables it, and the following line in /etc/sysctl.conf makes it persistent:
     338{{{
     339net.inet.ip.forwarding=1
     340}}}
     341
     342=== with `ufw` ===
     343source: https://nowhere.dk/articles/tip_nat_with_ubuntus_ufw_firewall
     344
     345`ufw` is your standard Linux firewall, and comes with Ubuntu server edition. Turning a multi-interface Linux box into a router is a matter of the following steps:
     346 1. configure IP forwarding
     347edit /etc/default/ufw :
     348{{{
     349DEFAULT_FORWARD_POLICY="ACCEPT"
     350}}}
     351 2. set up IP masquerading in `ufw`   
     352edit /etc/ufw/before.rules, just after the header :
     353{{{
     354# nat Table rules
     355 *nat
     356 :POSTROUTING ACCEPT [0:0]
     357
     358 # Forward traffic through ppp0 - Change to match you out-interface
     359 -A POSTROUTING -s 192.168.1.0/24 -o ppp0 -j MASQUERADE
     360
     361 # don't delete the 'COMMIT' line or these nat table rules won't
     362 # be processed
     363 COMMIT
     364}}}
     365The address block after -s should match the address block behind the NAT firewall.
     366
     367 3. restart ufw:
     368{{{
     369sudo ufw disable && sudo ufw enable
     370}}}
     371
     372=== with `pf` ===
     373`pf` is the OpenBSD packet filter, a piece of software intended for heavy-duty packet filtering/firewalls and comes with some Berkeley UNIX derivatives. 
     374Assuming you have IP forwarding enabled, the following configuration in /etc/pf.conf should give you a NAT firewall:
     375{{{
     376ext_if="bge0"
     377int_if="em0"
     378external_addr="192.168.203.155"
     379internal_net="192.168.1.0/24"
     380nat on $ext_if from $internal_net to any -> ($ext_if)
     381pass in all
     382pass out all
     383}}}
     384`ext_if` is the interface facing the external network, and `int_if` is the interface connected to your NATed net.
     385Once saved, start `pf`:
     386{{{
     387sudo pfctl -e -f /etc/pf.conf
     388}}}
     389If it throws errors, make sure that the kernel module (pf.ko or something similar) is loaded.
     390
     391== FreeBSD `ifconfig` shinanigans. ==
     392FreeBSD's `ifconfig` combines the features of `ifconfig` and `iwconfig` in Linux (and probably more). For example, you can get a list of AP's, you can do:
     393{{{
     394$ ifconfig wlan0 list scan
     395SSID/MESH ID    BSSID              CHAN RATE   S:N     INT CAPS
     396kitchen         08:86:3b:a0:20:f2    6   54M   8:0    100 EP   HTCAP WPA RSN WME WPS
     397WINMAIN         c4:7d:4f:37:2d:f0    6   54M  15:0    102 ES   HTCAP WME
     398front.door      08:86:3b:d7:f4:6c    6   54M   5:0    100 EP   RSN HTCAP WME WPS
     399}}}
     400And so on.
     401
     402Another thing that you can do (unintentionally or otherwise) is to assign multiple network addresses to a single interface. The `add` keyword lets you do this intentionally:
     403{{{
     404$ sudo ifconfig wlan0 inet 192.168.206.1 add
     405$ ifconfig wlan0
     406wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
     407        ether 00:1c:bf:9a:61:c7
     408        inet 192.168.206.120 netmask 0xffffff00 broadcast 192.168.206.255
     409        inet 192.168.206.1 netmask 0xffffff00 broadcast 192.168.206.255
     410        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
     411        media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11g
     412        status: associated
     413        ssid WINMAIN channel 6 (2437 MHz 11g) bssid c4:7d:4f:37:2d:f0
     414        country US authmode OPEN privacy OFF txpower 0 bmiss 7 scanvalid 60
     415        protmode CTS bintval 102
     416}}}
     417On wired interfaces, assigning addresses with `ifconfig [iface] inet [address]` will have the same effect, which may not be what you want, especially when you expect the old address to just be replaced by your new one^2^. In this case, you can remove the unwanted address with `-alias`:
     418{{{
     419$ sudo ifconfig wlan0 inet 192.168.206.1 -alias
     420$ ifconfig wlan0
     421wlan0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
     422        ether 00:1c:bf:9a:61:c7
     423        inet 192.168.206.120 netmask 0xffffff00 broadcast 192.168.206.255
     424        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
     425        media: IEEE 802.11 Wireless Ethernet OFDM/36Mbps mode 11g
     426        status: associated
     427        ssid WINMAIN channel 6 (2437 MHz 11g) bssid c4:7d:4f:37:2d:f0
     428        country US authmode OPEN privacy OFF txpower 0 bmiss 7 scanvalid 60
     429        protmode CTS bintval 102
     430}}}
     431
     432Otherwise, this feature is pretty handy for quickly adding a IP interface to an interface for, say (as a silly example), creating a carted-off piece of network for a host you don't want to put on the main network, but you still need to access.   
     433
    425434----
    426435== Quick Printing Setup. == #print