| 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. |
| | 297 | ---- |
| | 298 | = Networking-related odds and ends = #net |
| | 299 | Various non-experimental network setups, usually done for convenience. |
| | 300 | == Disabling SSH timeout == |
| | 301 | source: http://docs.oseems.com/application/ssh/disable-timeout |
| | 302 | |
| | 303 | You can essentially prevent SSH from timing out after a long idle period by adding the following to /etc/ssh/ssh_config : |
| | 304 | {{{ |
| | 305 | ServerAliveInterval 100 |
| | 306 | }}} |
| | 307 | |
| | 308 | 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 : |
| | 309 | {{{ |
| | 310 | ClientAliveInterval 30 |
| | 311 | TCPKeepAlive yes |
| | 312 | ClientAliveCountMax 99999 |
| | 313 | }}} |
| | 314 | |
| | 315 | And restarting sshd: |
| | 316 | {{{ |
| | 317 | /etc/init.d/ssh restart |
| | 318 | }}} |
| | 319 | |
| | 320 | |
| | 321 | == NAT boxes. == |
| | 322 | 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]] |
| | 323 | On Linux, the command |
| | 324 | {{{ |
| | 325 | sudo sysctl -e net.ipv4.ip_forward=1 |
| | 326 | }}} |
| | 327 | at the shell enables it. For persistence, add the following line to /etc/default/ufw: |
| | 328 | {{{ |
| | 329 | net.ipv4.ip_forward=1 |
| | 330 | }}} |
| | 331 | |
| | 332 | [[BR]] |
| | 333 | Similarly for FreeBSD (assuming you have `sudo` installed), |
| | 334 | {{{ |
| | 335 | sudo sysctl net.inet.ip.forwarding=1 |
| | 336 | }}} |
| | 337 | enables it, and the following line in /etc/sysctl.conf makes it persistent: |
| | 338 | {{{ |
| | 339 | net.inet.ip.forwarding=1 |
| | 340 | }}} |
| | 341 | |
| | 342 | === with `ufw` === |
| | 343 | source: 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 |
| | 347 | edit /etc/default/ufw : |
| | 348 | {{{ |
| | 349 | DEFAULT_FORWARD_POLICY="ACCEPT" |
| | 350 | }}} |
| | 351 | 2. set up IP masquerading in `ufw` |
| | 352 | edit /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 | }}} |
| | 365 | The address block after -s should match the address block behind the NAT firewall. |
| | 366 | |
| | 367 | 3. restart ufw: |
| | 368 | {{{ |
| | 369 | sudo 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. |
| | 374 | Assuming you have IP forwarding enabled, the following configuration in /etc/pf.conf should give you a NAT firewall: |
| | 375 | {{{ |
| | 376 | ext_if="bge0" |
| | 377 | int_if="em0" |
| | 378 | external_addr="192.168.203.155" |
| | 379 | internal_net="192.168.1.0/24" |
| | 380 | nat on $ext_if from $internal_net to any -> ($ext_if) |
| | 381 | pass in all |
| | 382 | pass out all |
| | 383 | }}} |
| | 384 | `ext_if` is the interface facing the external network, and `int_if` is the interface connected to your NATed net. |
| | 385 | Once saved, start `pf`: |
| | 386 | {{{ |
| | 387 | sudo pfctl -e -f /etc/pf.conf |
| | 388 | }}} |
| | 389 | If it throws errors, make sure that the kernel module (pf.ko or something similar) is loaded. |
| | 390 | |
| | 391 | == FreeBSD `ifconfig` shinanigans. == |
| | 392 | 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: |
| | 393 | {{{ |
| | 394 | $ ifconfig wlan0 list scan |
| | 395 | SSID/MESH ID BSSID CHAN RATE S:N INT CAPS |
| | 396 | kitchen 08:86:3b:a0:20:f2 6 54M 8:0 100 EP HTCAP WPA RSN WME WPS |
| | 397 | WINMAIN c4:7d:4f:37:2d:f0 6 54M 15:0 102 ES HTCAP WME |
| | 398 | front.door 08:86:3b:d7:f4:6c 6 54M 5:0 100 EP RSN HTCAP WME WPS |
| | 399 | }}} |
| | 400 | And so on. |
| | 401 | |
| | 402 | 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: |
| | 403 | {{{ |
| | 404 | $ sudo ifconfig wlan0 inet 192.168.206.1 add |
| | 405 | $ ifconfig wlan0 |
| | 406 | wlan0: 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 | }}} |
| | 417 | 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`: |
| | 418 | {{{ |
| | 419 | $ sudo ifconfig wlan0 inet 192.168.206.1 -alias |
| | 420 | $ ifconfig wlan0 |
| | 421 | wlan0: 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 | |
| | 432 | 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. |
| | 433 | |