Linux Guides, Tips and Tutorials | LinuxScrew https://www.linuxscrew.com LinuxScrew is a Linux resource that contains many useful guides on Linux, programming, networking, and more. Fri, 28 May 2021 12:37:42 +0000 en-US hourly 1 https://wordpress.org/?v=5.7.2 https://www.linuxscrew.com/wp-content/uploads/2020/10/favicon-7-48x48.png Linux Guides, Tips and Tutorials | LinuxScrew https://www.linuxscrew.com 32 32 JavaScript vs Java – What’s the Difference Which to Use in 2021? https://www.linuxscrew.com/javascript-vs-java https://www.linuxscrew.com/javascript-vs-java#respond Mon, 07 Jun 2021 10:42:21 +0000 https://www.linuxscrew.com/?p=7640 Here’s a clear article on what makes Java and JavaScript different – and some information to help you make the choice on which to learn and use for your projects in 2021. First up, it’s important to clarify that JavaScript and Java are not the same things! They just have similar names. It’s stupid, and they should have called… Read More »JavaScript vs Java – What’s the Difference Which to Use in 2021?

View the original article from LinuxScrew here: JavaScript vs Java – What’s the Difference Which to Use in 2021?

]]>
Here’s a clear article on what makes Java and JavaScript different – and some information to help you make the choice on which to learn and use for your projects in 2021.

First up, it’s important to clarify that JavaScript and Java are not the same things!

They just have similar names. It’s stupid, and they should have called JavaScript something else (and tried to re-badge it ECMA Script, which is also a terrible name), but the JavaScript name stuck. Now we’re all stuck with two different programming languages with pretty much the same name.

JavaScript and Java are separate languages that are wholly independent of each other and use different syntax and run in different places.

What is JavaScript?

JavaScript was developed in the mid-1990s for the Netscape web browser. It was intended to be used to add interactive elements to web pages – things like buttons that make a click sound when clicked, pop-up overlays, drop-down menus, and spinning text.

It rapidly grew to be used to power all sorts of browser-based tools, from games to email clients to full office application suites.

Over time it has been developed into a full-featured programming language, which can even be run outside the web browser and can now be used to develop desktop and mobile applications which run independently of a web browser.

JavaScript is popular with mobile app developers, website developers, and home tinkerers.

We’ve already compared and explained JavaScript to other similar-sounding languages and frameworks in the following articles:

What is Java?

Java is a completely different programming language developed in the early 1990s by Sun Microsystems (may they rest in peace).

Java doesn’t run in a web browser, but code written in Java on one platform can work on another as Java executes inside a virtual machine – a virtual environment that smooths over the differences in different operating systems and lets code written once run anywhere.

Due to this, it has become very popular, especially with client-server web applications that need to run on various platforms.

Java is popular with professional organizations looking to build large, networked applications – and is a popular learning tool at universities.

Which One Should I Use?

As always, no one language can always be directly compared to another.

Both JavaScript and Java are incredibly popular as they both serve different needs – so you’ll need to consider that when choosing.

The syntax differs between them, but one is no more complex than the other once you get past some beginner hurdles.

Here are some dot-points about what both Java and JavaScript have in common:

  • Both are object-oriented with a simple, readable syntax
  • Both have free development tools and learning resources
  • Both can be run almost anywhere, but js wins (Cordova)
  • Both are popular with many learning resources, but js wins

If you’re looking to develop desktop or client/server applications with high reliability, are looking to enter an industry where Java is the standard, or are just looking to learn and aren’t concerned about being able to run your code on Apple mobile devices, Java is a fine choice.

If you’re looking to do all of that but also want to build fancy websites with animations, run your code on Apple devices, and are less concerned about industry suitability – JavaScript will suit you well.

Historically, there were big differences between the two. As JavaScript can now run outside of the browser and be used to build mobile apps with tools like Ionic Framework – the use-cases for both languages have become quite similar.

Which one you use really just depends on whether you expect to need to write code for a specific industry that uses Java, whether you want to use JavaScript to build websites, or are just tinkering at home.

View the original article from LinuxScrew here: JavaScript vs Java – What’s the Difference Which to Use in 2021?

]]>
https://www.linuxscrew.com/javascript-vs-java/feed 0
Delete Files Older Than X Days/Hours in Bash [Examples] https://www.linuxscrew.com/bash-delete-files-older-than https://www.linuxscrew.com/bash-delete-files-older-than#respond Sun, 06 Jun 2021 10:42:20 +0000 https://www.linuxscrew.com/?p=7645 This article will show you how to delete files older than a given number of days (or hours/minutes) manually or automatically via a Bash script. Examples included. Removing files older than a certain number of days (or minutes, or hours) makes use of two Linux commands – rm and find. Deleting Files with rm First up, the rm command. The rm command is… Read More »Delete Files Older Than X Days/Hours in Bash [Examples]

View the original article from LinuxScrew here: Delete Files Older Than X Days/Hours in Bash [Examples]

]]>
This article will show you how to delete files older than a given number of days (or hours/minutes) manually or automatically via a Bash script. Examples included.

Removing files older than a certain number of days (or minutes, or hours) makes use of two Linux commands – rm and find.

Deleting Files with rm

First up, the rm command. The rm command is used to remove files and directories in Linux. Here’s a whole article about how it’s used:

rm Command in Linux [With Examples]

Passing a Filtered List of Files to rm

The next component, the find command. The find command is used to find files based on a set of criteria – in this case, the age of the file (time passed since it was modified). Here’s our article on the find command:

Find Command in Linux [With Useful Examples]

Putting Them Together – Example

Using find and rm together:

find /path/to/files/* -mtime +7 -exec rm {} \;

What’s happening here?

  • find is called on the directory /path/to/files
    • the -mtime option is passed to find with the value +7 passed to it – meaning files modified more than 7 days ago
    • The exec option is passed to find with the command to run against each matching file
  • rm is called by the -exec option in find
    • it will remove all files matching the conditions given to find
    • The curly braces, slash, and semicolon at the end of the line signal the end of the command find should run on each matching file

Hours, Minutes Instead of Days

To use minutes instead of days as the unit of time, you can substitute -mmin instead of -mtime.

find /path/to/files/* -mmin +30 -exec rm {} \;

The above example would delete files older than 30 minutes.

Making it into A Script

Rather than typing this out, you could make it into a script

#!/bin/bash

find /path/to/files/* -mtime +7 -exec rm {} \;

Save the above snippet into a file (named deletescript.sh, for example), and then it can be called by running:

./deletescript.sh

You could also create an alias for the command if you want to run it from anywhere.

Scheduling Deletion of Old Files

If you want to run the command automatically at a set interval, add it to your crontab. The crontab file is where a user’s scheduled tasks are kept in Linux, and it can be edited by running:

crontab -e

On running the above, the crontab editor will be displayed. Simply append the following to the file to run the script every day:

@daily find /path/to/files/* -mtime +7 -exec rm {} \;

View the original article from LinuxScrew here: Delete Files Older Than X Days/Hours in Bash [Examples]

]]>
https://www.linuxscrew.com/bash-delete-files-older-than/feed 0
Bash Aliases – What They Are and How To Use Them https://www.linuxscrew.com/bash-aliases https://www.linuxscrew.com/bash-aliases#respond Sat, 05 Jun 2021 10:42:18 +0000 https://www.linuxscrew.com/?p=7654 If you live in the Linux Shell/Terminal, aliases are a massive timesaver. Here’s how to create your own Bash aliases, with examples. What is an Alias in Bash/Linux Shell? An alias is a shortcut to a longer command. It’s similar to a keyboard shortcut – like the CTRL + C key combination is a shortcut to the copy command in many graphical operating… Read More »Bash Aliases – What They Are and How To Use Them

View the original article from LinuxScrew here: Bash Aliases – What They Are and How To Use Them

]]>
If you live in the Linux Shell/Terminal, aliases are a massive timesaver. Here’s how to create your own Bash aliases, with examples.

What is an Alias in Bash/Linux Shell?

An alias is a shortcut to a longer command. It’s similar to a keyboard shortcut – like the CTRL + C key combination is a shortcut to the copy command in many graphical operating systems (saving the time in dragging your mouse across the screen and clicking multiple menus to reach the command), aliases are shortcuts to longer terminal commands (saving time typing out the full command).

Bash provides aliasing functionality built-in, as do many other Linux Shells, including zsh, which shares similar syntax.

The examples in this article should work with both Bash and Zsh.

Creating an alias

The alias command is used to create an alias.

alias and unalias Command Syntax

Here’s the syntax for the alias command:

alias OPTIONS SHORTCUT=COMMAND

And here’s the syntax for the unalias command:

unalias OPTIONS SHORTCUT

Note that:

  • OPTIONS is a list of optional flags from the below table
  • SHORTCUT is the shortcut you wish to be able to type to execute COMMAND
    • it can only consist of alphanumeric characters, dashes, and underscores
  • COMMAND should be the command you wish to be executed when SHORTCUT is entered
    • The = character should separate SHORTCUT and COMMAND with no spaces between
    • If COMMAND contains spaces, you will need to contain it within quotes
    • An alias can only be used as the first word in a command
alias Command Options
-p List currently defined aliases (only for alias command)
-a Clear all aliases (only for unalias command)

Temporarily Assigning an Alias in Bash

When the alias command has been executed, and an alias has been created, it is available only for the current session. That is, the terminal window you have open or the login session you have with a remote server.

Exiting the terminal, logging out, rebooting, etc., will clear all aliases, and they will not be recreated for future sessions.

Example – Creating and Using an Alias

Here’s a simple example of defining an alias:

alias say_hello='echo "Hello LinuxScrew!"'

Above, an alias say_hello is defined, which will run the command:

echo  "Hello LinuxScrew!"

But now, instead of having to type all of that out, the alias can be run instead:

say_hello

Even for this simple example, a lot of typing is saved. For more complex commands, aliases can save a lot of typing or remembering long command strings.

Permanently Assigning an Alias in Bash

Want to make an alias permanent so that it survives window closures, logouts, and reboots? Add your alias commands to the .bashrc file to reload them at each login:

nano ~/.bashrc

The .bashrc file defines the behavior of the Bash shell for your user account. Simply append your alias commands to the end of the file, one on each line, to execute those alias commands automatically each time you log in.

Listing Existing Alias

List existing aliases by running the alias command with the -p option:

alias -p

Removing an Alias

To remove an alias, use unalias:

unalias say_hello

Clearing All Alias

Clear all aliases by running the alias command with the -a option:

alias -a

Zsh Extras

While the above will work in the Zsh shell, Zsh also includes a bunch of other aliasing options:

http://zsh.sourceforge.net/Intro/intro_8.html

Zsh is increasing in popularity due to becoming the default shell in Apple’s macOS. However, Bash is still the default in most Linux operating systems, so I won’t delve too deeply into the additional functionality of Zsh to avoid confusion – that’s for another article!

View the original article from LinuxScrew here: Bash Aliases – What They Are and How To Use Them

]]>
https://www.linuxscrew.com/bash-aliases/feed 0
OpenWrt: Set up a Basic Network Including WiFi Bridge, IP Address, DHCP https://www.linuxscrew.com/openwrt-network-setup https://www.linuxscrew.com/openwrt-network-setup#respond Fri, 04 Jun 2021 10:42:17 +0000 https://www.linuxscrew.com/?p=7659 This article will show you how to configure a basic network with WiFi Bridging, DHCP on a fresh install of OpenWrt – with explanations and screenshots. This guide follows on from LinuxScrew’s guide to setting up OpenWrt on a BT HomeHub 5 – but you can follow along on any device (including a Raspberry Pi!). This… Read More »OpenWrt: Set up a Basic Network Including WiFi Bridge, IP Address, DHCP

View the original article from LinuxScrew here: OpenWrt: Set up a Basic Network Including WiFi Bridge, IP Address, DHCP

]]>
This article will show you how to configure a basic network with WiFi Bridging, DHCP on a fresh install of OpenWrt – with explanations and screenshots.

This guide follows on from LinuxScrew’s guide to setting up OpenWrt on a BT HomeHub 5 – but you can follow along on any device (including a Raspberry Pi!).

This article assumes you have an OpenWrt device you wish to start using. We’ll start by connecting it to your home WiFi network to get it online and then setting it up to broadcast its own WiFi network with its own DNS and DHCP settings.

1. Power Up and Connect

Power up your OpenWrt device and plug it into your computer via Ethernet.

By default OpenWrt should have no wireless networks defined -and we’ll modify the configuration anyway, so a wired connection will be necessary.

If you can’t access your OpenWrt device via a web browser on the default IP range, check if it conflicts with your existing network. You may have to disconnect your computer from your home network while you set things up initially so that you aren’t connected to two conflicting networks.

The easiest way to do this is often to enable flight mode, which will disable your WiFi connection and leave only your wired connection to OpenWrt.

2. Log In to OpenWrt

Head to the default IP address used by OpenWrt:

http://192.168.1.1

…and login.

openwrt basic network 00001

You’ll see the following page with a bunch of stats about your router:

openwrt basic network 00002

Change IP Address and Set Up DHCP

The first step is the change the IP address of OpenWrt and the DHCP server it hosts.

Why? Because if your home network is also set up to use the network 192.168.1.0/24, OpenWrt will be struggling to find the correct routes to reach it, as it uses the same network addresses by default.

Click here to find out more about networks, IP addresses, and subnets.

DHCP (Dynamic Host Configuration Protocol) automatically assigns IP addresses on your network. We’ll need to set a new IP for the router, which will also change the address range which DHCP will assign.

So, before continuing, we need to set up OpenWrt with some new IP address details. Navigate to:

Network -> Interfaces

And click on the Edit button next to the LAN interface.

Under General Settings, find the IPv4 Address entry.

Currently, it is 192.168.1.1. This needs to be changed to something less common and less likely to conflict. I have chosen:

10.123.123.1

Which should steer well clear of the network address ranges commonly assigned by consumer routers.

openwrt basic network 00008

If you decide to use a different range, make sure it complies with the rules for local IP addresses, so you don’t get a conflict!

Fill in the new IP address, hit Save.

This time (and only this time!), rather than clicking Save and Apply at the bottom of the page, toggle the dropdown next to it and select Apply Unchecked, then click the Apply Unchecked button to apply the changes.

As the device’s IP address will be changing, the configuration will not be able to connect to it afterward to confirm the change, and the configuration will rollback. So we don’t want to check the configuration after it is changed.

openwrt basic network 00009

As the network configuration has changed, you may need to disconnect and reconnect the ethernet cable to your OpenWrt device or restart networking to refresh the DHCP assigned address on your computer.

You should be able to now reconnect to your OpenWrt device at the address

10.123.123.1

If it’s been a few minutes and you still can’t connect, try hard-rebooting your OpenWrt device by powering it off for a minute and powering it back on.

Set Up WiFi Bridge

Navigate to:

Network -> Wireless

From the dropdown menus at the top of the page to access the WiFi settings page:

openwrt basic network 00003

You’ll see a list of wireless network interfaces and their status.

Most devices will have two WiFi interfaces – a legacy 802.11bgn and a newer 5Ghz 802.11nac interface. This is usually so that older devices can connect to the router on the legacy interface and newer ones on the faster 5GHZ.

Rather than doing this, let’s connect the legacy WiFi interface to our existing home WiFi network and set up the 5Ghz interface as the network broadcast by OpenWrt. This means old devices won’t be able to connect, but who cares.

This will get the OpenWrt box online wirelessly, and then let us configure a WiFi network provided by OpenWrt with all of the extra features that allow for, without having to alter the configuration of the existing home network (which is sometimes a good idea if you have family members working from home you don’t want to disturb).

Connect to Your Home Network

To connect OpenWrt to your home network, click the Scan button next to the legacy interface.

openwrt basic network 00004

Click on the Join Network button next to your network, and you’ll see a configuration screen:

openwrt basic network 00005

Check Replace wireless configuration to ensure any previous or default configuration for this interface is removed.

Enter your WiFI passphrase.

Check Lock to BSSID. This is good for security – it helps stop someone nearby from imitating your home network router and tricking OpenWrt into connecting to it.

Leave everything else as-is and hit the green Submit button.

openwrt basic network 00006

Leave everything on the next page as it is – this is the newly generated configuration. Hit Save.

openwrt basic network 00007

The configuration has been updated but not applied, as services need to restart. You can see the 9 pending changes there next to the interface.

Click on Save and Apply to apply the new configuration.

Reboot

As the routes will have changed (OpenWrt will use your home networks DHCP and DNS settings to get online) – you may need to reboot for the full configuration change to take effect.

Navigate to:

System -> Reboot

…from the navigation dropdowns, hit the Perform Reboot button, and wait for a bit.

Your OpenWrt device is now online via your home WiFi network!

Testing the New Connection

OpenWrt includes tools to check that you are connected to the network:

Go to:

Network -> Diagnostics

…from the dropdowns at the top of the page.

Next, click on the IPv4 Ping button.

Wait a bit, and you should see something like this on success:

PING openwrt.org (139.59.209.225): 56 data bytes
64 bytes from 139.59.209.225: seq=0 ttl=54 time=30.596 ms
64 bytes from 139.59.209.225: seq=1 ttl=54 time=23.814 ms
64 bytes from 139.59.209.225: seq=2 ttl=54 time=23.686 ms
64 bytes from 139.59.209.225: seq=3 ttl=54 time=23.381 ms
64 bytes from 139.59.209.225: seq=4 ttl=54 time=29.441 ms

--- openwrt.org ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 23.381/26.183/30.596 ms

If there is a problem, you’ll get a message telling you what went wrong.

Set up an OpenWrt WiFi Network

At this stage, OpenWrt is online and up to date.

Your computer should also be online via the wired connection to the WRT box.

Time to add that second WiFi connection on OpenWrt so you can remove the ethernet cable and connect to it wirelessly.

The title of this article calls this link between two Wifi networks a ‘bridge.’ Technically, the way things will be configured isn’t a bridge – your home WiFi network and the WiFi network provided by OpenWrt will be isolated from each other.

The setup which will result is called ‘Double NAT‘ – the OpenWrt router won’t be connected directly to the internet; it will be connected to another router (your home WiFi router). This can cause issues with some services like hosting public internet servers and some online games but can be preferable for new users so that they don’t have to mess with their home network and risk-taking themselves completely offline.

Once you’re an OpenWrt master, you can replace your home router with your OpenWrt device and remove the ‘Double NAT’ limitations.

Navigate back to:

Network -> Wireless

You’ll see Your two radio WiFi interfaces – one connected from the previous steps, one listed as Device not active.

Click on the Edit button next to the OpenWRT network under the inactive 5Ghz interface.

Scroll down to Interface Configuration:

openwrt basic network 00011

Change the SSID (wireless network name) if you like, and assign the new WiFi network to the LAN network.

Click on the Wireless Security Tab.

Select WPA2-PSK (Strong Security), and enter your Key (network password).

It’s essential to make sure you set a wireless key! Your network will be insecure without one!

Click Save.

Then click Save and Apply at the bottom of the page.

Now you can safely enable the OpenWRT WiFi network by clicking the Enable button adjacent.

openwrt basic network 00012

You will see that both WiFi interfaces are now active.

WARNING: Make sure every WiFi network in the list has an Encryption method listed next to it – if it doesn’t, anyone can connect!

Interfaces in mode ‘Master ‘are hosting a WiFi network, and those set to ‘Client‘ are connected to your home WiFi network.

As the new network was added to the ‘LAN‘ network, it will be on the same network as the ethernet ports on your OpenWrt device and already be configured to connect to the internet through your home WiFi network.

You can now disconnect your ethernet cable and connect to your new OpenWrt WiFi network.

Uh Oh – How to Recover from Mistakes

If something went wrong, check out the OpenWrt wiki on how to recover a botched configuration:

https://openwrt.org/docs/guide-user/troubleshooting/failsafe_and_factory_reset

Done!

You’re up and running – a fully functional network hosted on your OpenWRT box.

Your home network is as it was, and you can muck about with OpenWRT as much as you like without messing with it – the ‘Double NAT’ situation isn’t perfect, but you can now start getting familiar with OpenWRT and configuring your own segregated networks, file shares, and more – stay tuned for more articles!

View the original article from LinuxScrew here: OpenWrt: Set up a Basic Network Including WiFi Bridge, IP Address, DHCP

]]>
https://www.linuxscrew.com/openwrt-network-setup/feed 0
OpenWRT: Secure DNS over TLS with LuCI [No Command Line] https://www.linuxscrew.com/secure-dns-tls-openwrt-luci https://www.linuxscrew.com/secure-dns-tls-openwrt-luci#respond Thu, 03 Jun 2021 10:42:16 +0000 https://www.linuxscrew.com/?p=7677 This article will show you a quick and clean way of getting secure DNS over TLS running on OpenWRT – without resorting to the command line. If follows on from our other OpenWrt Articles. We’ll be using stubby – a local DNS resolver that will encrypt local DNS queries and forward them to an external secure DNS… Read More »OpenWRT: Secure DNS over TLS with LuCI [No Command Line]

View the original article from LinuxScrew here: OpenWRT: Secure DNS over TLS with LuCI [No Command Line]

]]>
This article will show you a quick and clean way of getting secure DNS over TLS running on OpenWRT – without resorting to the command line.

If follows on from our other OpenWrt Articles.

We’ll be using stubby – a local DNS resolver that will encrypt local DNS queries and forward them to an external secure DNS resolver Provided by Cloudflare.

Why Cloudflare?

Because it’s the default secure DNS resolver in the default stubby configuration, that means we don’t have to edit the config files, and Cloudflare’s servers are fine for general use.

Install Stubby

Log in to your OpenWrt router and navigate to:

System -> Software

… then, press the Update Lists button to get the list of installable packages. When it’s done, dismiss the box with the details of the downloaded lists.

In the Filter text box, enter the text ‘stubby’ to find the package we need.

openwrt secure dns 00002

Click the Install button next to the stubby package. Confirm by pressing Install again in the popup that appears.

When it’s done, dismiss the popup with the installation summary.

Set Stubby to Start Automatically

Navigate to:

System -> Startup

… scroll down to the stubby entry and ensure it is set to Enabled. Then, press Start next to the stubby entry to make sure it’s running.

openwrt secure dns 00003

Update Network Configuration to use Stubby/Secure DNS

Navigate to:

Network -> DHCP and DNS

…and go to the Resolve and Hosts Files tab. Check Ignore resolve file. This tells OpenWrt to ignore its own DNS configuration as it will be using stubby instead.

Hit Save and Apply to confirm the change.

Next, go to the General Settings tab. Scroll down to the DNS Forwardings setting – we will need to add two entries here:

127.0.0.1#5453
0::1#5453

openwrt secure dns 00001

This tells OpenWrt to use the newly installed stubby software package to resolve DNS – it runs on port 5453. The first entry is for IPv4, the second for IPv6.

Scroll down and hit Save and Apply to confirm the change. Make sure the change is applied by going to

System -> Startup

And restarting the dnsmasq service. You could also reboot OpenWrt to make sure all configuration is reloaded.

All done!

Test Secure DNS

Head over to:

https://www.cloudflare.com/ssl/encrypted-sni/

…and press Check My Browser.

If everything’s working, you’ll see green checkmarks for Secure DNS and DNSSEC.

View the original article from LinuxScrew here: OpenWRT: Secure DNS over TLS with LuCI [No Command Line]

]]>
https://www.linuxscrew.com/secure-dns-tls-openwrt-luci/feed 0
Segregating Devices and Networks in OpenWrt [Tutorial] https://www.linuxscrew.com/openwrt-segregated-wifi https://www.linuxscrew.com/openwrt-segregated-wifi#respond Wed, 02 Jun 2021 10:42:15 +0000 https://www.linuxscrew.com/?p=7687 This article will show you how to keep your devices separate on your OpenWRT managed network and follows the steps taken to set up a basic WiFi network covered here. Why would you want to keep your devices from talking to each other on a local network? I repair other people’s computers – other people who… Read More »Segregating Devices and Networks in OpenWrt [Tutorial]

View the original article from LinuxScrew here: Segregating Devices and Networks in OpenWrt [Tutorial]

]]>
This article will show you how to keep your devices separate on your OpenWRT managed network and follows the steps taken to set up a basic WiFi network covered here.

Why would you want to keep your devices from talking to each other on a local network?

I repair other people’s computers – other people who may not be too careful about what websites they visit. If I need to connect one of these computers to my home network, I want to make sure that they can’t reach any of my own devices to potentially infect them.

I also repair old vintage computers. These can be usefully networked for transferring files and stuff like that, but I don’t want them to have any access to the internet – I’ll want to have some firewall rules to cover that scenario too.

The following covers the steps taken to get everything set up to cover the above.

Creating a Separate Network

First, we need to create a new network to which these questionable devices will connect to. By default, there is a LAN network, so I’ll call this second network BADLAN.

Navigate to:

Network -> Interfaces

…from the dropdowns at the top of the page.

openwrt segregated 1

A list of the existing networks/interfaces will be displayed – click on the Add New Interface button at the end of the list.

Enter the name for the new interface and set Protocol to Static address.

openwrt segregated 2

Click Create Interface.

Next, fill in the IP address for the OpenWRT router on the new network. My existing network uses a 10.123.123.0/24 subnet, so I’ll make this new network use the 10.123.124.0/24 subnet and assign the router 10.123.124.1 address.

openwrt segregated 3

Next, go to the Firewall Settings tab, click in the Assign firewall zone dropdown, fill in the custom name for the new firewall zone (in this case, ‘badlan‘), and hit enter. A new firewall zone with that name will be created for the new network so we can later direct traffic.

openwrt segregated 11

To learn about IP subnets and how they work, check out this article.

Click over to the DHCP Server tab and click Setup DHCP Server. The defaults will be fine, so go ahead and click save to finish.

openwrt segregated 4

openwrt segregated 5

Scroll to the bottom of the page and hit Save and Apply to finish this step.

openwrt segregated 6

Segregated WiFi Network

Many devices can host more than one wireless network on each WiFi interface. So I’m just going to add a second WiFi network to my OpenWrt Router and set it to not allow connected devices to talk to each other. This second WiFi network can then be assigned to the BADLAN interface created in the previous step.

First, navigate to:

Network -> Wireless

…from the navigation dropdowns.

openwrt segregated 7

You can see the existing ‘OpenWRT‘ network on the radio0 interface, which provides a regular wireless network.

Click on the Add button next to the radio0 interface to add a second WiFi network to it.

Fill out the ESSID (WiFi network name), click on the Network dropdown, and select the previously created BADLAN network. This will keep things separate from the LAN network. I’ve called my WiFi network ‘BadWiFi.’

openwrt segregated 8

Next, click on the Wireless Security tab and select WPA2-PSK from the dropdown, then enter a key (password) to be used when connecting to the network.

openwrt segregated 9

Finally, navigate to the Advanced Settings tab and check Isolate Clients – this will prevent WiFi clients from seeing each other.

openwrt segregated 10

Click on the green Save button, then click Save and Apply at the bottom of the page to confirm the changes.

We’re done! WiFi clients connected to the new network will be on a separate network and will not communicate with each other.

Other Considerations

Not all devices will be stable when hosting multiple networks – your results may vary.

If your device doesn’t let you run more than one wireless network at once, you could add an additional WiFi interface using a USB WiFi dongle and host your segregated network from that.

If your device is struggling to host more than 2 WiFi networks, and you are using one of the WiFi interfaces as a wireless bridge, consider going wired to get internet to your OpenWRT box instead. Alternatively, you may have to live with a single, segregated WiFi network and simply turn your normal network on or off as needed.

Segregated Wired Network

This step is optional and only required if you plan to segregate devices connected to a wired network port.

This only works on the ports built into your OpenWrt Device – it won’t work on a connected network switch (unless it too is configurable, and you can set up VLAN flags on it).

I’m setting this all up on a BT HomeHub 5, which has multiple network ports, so it’s perfect for this situation.

In the previous step, we added a network called BADLAN, which is separate from the existing LAN network. If we want to segregate wired clients, we simply need to assign the physical ethernet port that client will be plugged into to the BADLAN network.

To do so, navigate to:

Network -> Switch

openwrt segregated 15

Click the Add VLAN button.

Make sure the CPU interface is set to tagged for the new VLAN so that it can be added to an interface later.

Set the ports for the new VLAN which you want to be assigned to your segregated network to untagged. Ensure those ports are set to OFF for any other VLANs:

openwrt segregated 17

In this case, I’ve set ports 3 and 4 on my router to be part of the segregated network by setting them to untagged.

It’s a bit confusing here – off obviously means the port is not part of the given VLAN – but tagged and untagged both mean that it is assigned to that VLAN. untagged is the one we want – it means the switch will accept normal ethernet traffic rather than VLAN tagged data from another managed switch.

Click Save and Apply.

Navigate to:

Network -> Interfaces

Click the edit button next to the BADLAN network and go to the Physical Settings tab.

Check Bridge Interfaces so that multiple interfaces can be selected.

Click on the Interfaces dropdown and check Switch VLAN: “eth0.3” to add the VLAN to the segregated network.

openwrt segregated 16

Click Save and then click Save and Apply at the bottom of the page to confirm changes.

Unlike wireless clients, devices on physical ports will be separated from the main LAN network but not each other.

Enabling the Internet for Segregated Network

Your segregated network allows clients to connect but currently has no internet connection! Let’s get that working next.

Head over to:

Network -> Firewall

Scroll down to the Zones section – you’ll see a diagram and some dropdowns showing how traffic is to be forwarded between your different firewall zones. lan is your local network, wan is the internet, and badlan is the new segregated network, which is currently set to reject all traffic.openwrt segregated 12

To allow traffic from badlan to wan, click on the blue Edit button to the right, and select wan from the Allow forward to destination zones: dropdown.

openwrt segregated 13

Your firewall table should now look something like this:

openwrt segregated 14

If things are yet to work, always try rebooting your router as the first troubleshooting step.

Hit the blue Save and apply button to finish up.

Local Connections Only

If you want a network where clients can talk to each other only and not the internet, repeat the steps above to create a new network with a different name, do not check Isolate Clients when creating the WiFi network, and simply skip the final internet-enabling step.

View the original article from LinuxScrew here: Segregating Devices and Networks in OpenWrt [Tutorial]

]]>
https://www.linuxscrew.com/openwrt-segregated-wifi/feed 0
Python Matrix (2D Array, NumPy), With Examples https://www.linuxscrew.com/python-matrix https://www.linuxscrew.com/python-matrix#respond Tue, 01 Jun 2021 09:39:06 +0000 https://www.linuxscrew.com/?p=7427 This article will explain what a matrix is and how to use them in the Python Programming Language with the NumPy library. What is a Matrix In mathematics and computer programming, a matrix is a two-dimensional array of values. It is a grid of columns and rows, with each position in the grid holding one… Read More »Python Matrix (2D Array, NumPy), With Examples

View the original article from LinuxScrew here: Python Matrix (2D Array, NumPy), With Examples

]]>
This article will explain what a matrix is and how to use them in the Python Programming Language with the NumPy library.

What is a Matrix

In mathematics and computer programming, a matrix is a two-dimensional array of values.

It is a grid of columns and rows, with each position in the grid holding one of these values.

It is an array because it’s a collection of elements with multiple elements, and it’s two-dimensional because the values exist at two coordinates (i.e., rows and columns).

Defining a Matrix using NumPy

NumPy is a Python library that adds support for large arrays and matrices and tools to manage them.

Here’s how to define a two-dimensional array, or matrix, in Python:

# Import the NumPy library 
import numpy

# Define an array - in this case the height (cm) and age (years) of several people
people = numpy.array([['Jim', 180, 20],
            ['Bob', 189, 18],
            ['Ann', 160, 21],
            ['Amy', 172, 25]])

print(people)

The above code defined the following matrix/array – each row is contained by [] (square brackets), and each value (or value in a column) is separated by a , (comma).

Jim 180 20
Bob 189 18
Ann 160 21
Amy 172 25

Accessing Matrix Row Value

Matrix positions are indexes – numbers that give a column or row position in their order from left to right or top to bottom. Indexes always start counting from 0 for the first position.

So, to print Jim’s details (the first row), access the matrix row index 0:

print(people[0])

Which will output:

['Jim', 180, 20]

Print Ann’s data from row index 2:

print(people[2])

Which will output:

['Ann', 160, 21]

Accessing Matrix Column Value

Column data can be retrieved from each row by also specifying the column index (which also starts counting at 0).

So, to retrieve the value of the first column in the first row (the person’s name):

print(people[0][0])

Which will return:

Jim

To retrieve the value of the 2nd row 3rd column (Bob’s age):

print(people[1][2])

Which will return:

18

Add/Delete/Update Rows

Adding a Single Row to a Matrix

The NumPy append function will append a row to a given matrix:

people = numpy.append(people, [['Tim', 191, 26]], axis=0)

The axis specified (0) is the row – the first coordinate in a two-dimensional array.

The updated people array in this example will replace the existing people array.

Adding Multiple Rows to a Matrix

In the above example, the array of data for Tim is contained in a separate set of square brackets – this is because the values to be appended are supplied as an array so that multiple rows can be added at once:

people = numpy.append(people, [['Tim', 191, 26], ['Pam', 195, 30]], axis=0)

Deleting Rows

Like the NumPy append() function, the delete() function accepts an array of values (in this case, a list of the row indexes to delete) and an axis:

people = numpy.delete(people, [1, 3], axis=0)

Above, the rows at indexes 1 and 3 were deleted – leaving the following array:

[['Jim' '180' '20']
['Ann' '160' '21']
['Tim' '191' '26']
['Pam' '195' '30']]

Updating Rows

Ann grew rapidly after drinking too many energy drinks – so her height must be updated. To update a row, simply re-assign the value at the same index as the existing row:

people[2] = ['Ann', 197, 21]

Above, the record for Ann at index 2 will be replaced with the new values.

Deleting Columns

The same delete() function used to delete rows is used to delete columns – simply change the index from 0 to 1 to specify the second coordinate of the two-dimensional array (i.e., the column):

people = numpy.delete(people, [[1, 2]], axis=1)

This will delete the columns at index 1 and 2 in the matrix, leaving only each person’s name.

Adding Columns

To add a column, use the NumPy insert function.

To add a ‘favorite color’ column to the end of the example people matrix, the following would be used:

people = numpy.insert(people, [3], [['red'], ['blue'], ['green'], ['purple']], axis=1)

Again, the people array is replaced with an updated copy with the new column inserted.

The axis is specified as 1, again because we are updating the column, which is the second array dimension.

The insert() function accepts several parameters – the array to be updated, followed by the index the column should be inserted at (in this case, the third column after nameheight, and age), the values to be inserted into the column, and the previously mentioned axis.

View the original article from LinuxScrew here: Python Matrix (2D Array, NumPy), With Examples

]]>
https://www.linuxscrew.com/python-matrix/feed 0
Remove/Delete Files/Directories in Linux with rm https://www.linuxscrew.com/linux-remove-delete-file-directory-rm https://www.linuxscrew.com/linux-remove-delete-file-directory-rm#respond Mon, 31 May 2021 09:39:24 +0000 https://www.linuxscrew.com/?p=7359 This article will outline how to delete files and directories in Linux with the rm command and give example usage. The rm Command in Linux Files and directories can be deleted from the shell/command line in Linux using the rm command. rm Command Syntax rm OPTIONS FILES Note that: OPTIONS is a list of options from the below table FILES is a list… Read More »Remove/Delete Files/Directories in Linux with rm

View the original article from LinuxScrew here: Remove/Delete Files/Directories in Linux with rm

]]>
This article will outline how to delete files and directories in Linux with the rm command and give example usage.

The rm Command in Linux

Files and directories can be deleted from the shell/command line in Linux using the rm command.

rm Command Syntax

rm OPTIONS FILES

Note that:

  • OPTIONS is a list of options from the below table
  • FILES is a list of files or directories (if the -r option is specified) to be removed
    • Multiple files or directories can be specified, separated by spaces

Options

Here are the most commonly used options for the rm command:

-f Ignore nonexistent files, never prompt
-i Prompt before every removal
-I Prompt once before removing more than three files or when removing recursively. Less intrusive than -i, while still giving protection against most mistakes
–one-file-system When removing a hierarchy recursively, skip any directory that is on a file system different from that of the corresponding command-line argument.
-r, -R, –recursive Remove directories and their contents recursively.
-v, –verbose Explain what is being done

For a full list of options, you can view the full rm command user manual by running:

man rm

Deleting/Removing a Single File

The default behavior of the rm command is to delete single files or a list of single files not contained in a directory.

rm file1

The full path to the file can also be specified:

rm /path/to/the/file

Deleting/Removing Multiple Files

rm file1 file2 file3 /path/to/file4

Deleting/RemovingDirectories

the -r (recursive) option will allow the rm command to delete a directory, as well as its contents.

rm -r directory1

The full path to the directory can also be specified:

rm -r /path/to/directory1

Prompting Before Deletion

If you want to confirm the deletion of tiles before them being removed, pass the -i (interactive) option:

rm -i file1 file2 file3

This can also be used when removing directories:

rm -i -r directory1

Be Sure!

Unlike many desktop environments (or if you’re coming from Windows or macOS), there’s no Recycle Bin or Trash Bin equivalent when you’re working in the Linux shell.

When a file is deleted, it’s deleted. You aren’t getting it back – so be careful!

If you aren’t sure whether you might need a file later, you can always designate a folder as your own trash bin and move files there until you’re sure they’re no longer required.

Keeping your files backed up is another (the best) method to guard against accidental deletion, system failure, theft, or any other disaster.

View the original article from LinuxScrew here: Remove/Delete Files/Directories in Linux with rm

]]>
https://www.linuxscrew.com/linux-remove-delete-file-directory-rm/feed 0
Copy a Table in MySQL/MariaDB – How To, With Examples https://www.linuxscrew.com/mysql-copy-table https://www.linuxscrew.com/mysql-copy-table#respond Mon, 31 May 2021 09:39:23 +0000 https://www.linuxscrew.com/?p=7366 This article will show you the BEST way to copy a table, with or without the data in it, in MySQL and MariaDB. Copying the Table with All Data in MySql The following code will copy a table including all data using the CREATE TABLE LIKE statement: CREATE TABLE new_table_name LIKE database_name.old_table_name; INSERT new_table_name SELECT… Read More »Copy a Table in MySQL/MariaDB – How To, With Examples

View the original article from LinuxScrew here: Copy a Table in MySQL/MariaDB – How To, With Examples

]]>
This article will show you the BEST way to copy a table, with or without the data in it, in MySQL and MariaDB.

Copying the Table with All Data in MySql

The following code will copy a table including all data using the CREATE TABLE LIKE statement:

CREATE TABLE new_table_name LIKE database_name.old_table_name;
INSERT new_table_name SELECT * FROM database_name.old_table_name;

There are other methods, some single line, but this is probably the best and simplest one.

Why did I choose this method? Because it copies the table indexes – including primary keys – and the AUTO_INCREMENT value so that when new data is inserted, it is inserted at the next available auto-increment rather than being inserted mid-table. Triggers are also copied. The new table is in the same state as the one it is being copied from.

The new table being created doesn’t have to be in the same database as the table being copied – in the example above, the new table will be created in the currently active database, and the database containing the table being copied can be specified.

Copying the Table Structure Only

To copy only the table structure, ignore the second line above and simply run:

CREATE TABLE new_table_name LIKE database_name.old_table_name;

This will create a new table with the same structure as the old one, but it will be completely empty of data.

As usual, never run untested queries on your production database — and always have an up-to-date backup of your data before running any queries.

View the original article from LinuxScrew here: Copy a Table in MySQL/MariaDB – How To, With Examples

]]>
https://www.linuxscrew.com/mysql-copy-table/feed 0
Move Files With the mv Command in Linux, With Examples https://www.linuxscrew.com/linux-move-file-mv https://www.linuxscrew.com/linux-move-file-mv#respond Sun, 30 May 2021 09:39:24 +0000 https://www.linuxscrew.com/?p=7351 This article will walk you through moving files in Linux with the mv command, with examples and tips on moving files safely. mv Syntax Moving files is done using the mv command, which has the following syntax mv OPTIONS SOURCE DESTINATION Note that: OPTIONS is a list of options from the below table SOURCE is the path to the file you… Read More »Move Files With the mv Command in Linux, With Examples

View the original article from LinuxScrew here: Move Files With the mv Command in Linux, With Examples

]]>
This article will walk you through moving files in Linux with the mv command, with examples and tips on moving files safely.

mv Syntax

Moving files is done using the mv command, which has the following syntax

mv OPTIONS SOURCE DESTINATION

Note that:

  • OPTIONS is a list of options from the below table
  • SOURCE is the path to the file you wish to move
  • DESTINATION is the path to the destination you want to move the file 2
    • This can include a new file name or simply be the path to a destination folder
    • mv will move SOURCE into DESTINATION if DESTINATION is a directory (or a link to a directory)
      • If DESTINATION is not a directory, mv will rename SOURCE to DESTINATION

Common mv Options

Here are some of the commonly used options when running mv, from the manual:

-b Make a backup of each existing destination file
-f, –force Do not prompt before overwriting
-i, –interactive Prompt before overwrite
-n, –no-clobber Do not overwrite an existing file
-u, –update Move only when the SOURCE file is newer than the destination file or when the destination file is missing.
-v, –verbose Explain what is being done

Additional options can be found in the mv manual by running:

man mv

Examples

Move file1 into directory1:

mv file1 directory1/

Rename file1 to file2:

mv file1 file2

Move file1 into directory1 and rename it to file2:

mv file1 directory1/file2

Move directory1 into directory2:

mv directory1/ directory2/

In the last example, if directory2 doesn’t exist, directory1 will be renamed to directory2. To only move it, and fail if the directory is not found, run:

mv directory1/ directory2/.

This will ensure directory2 exists before trying to move the file – the dot (.) specifies that the path should exist.

Sometimes it’s better to copy than move

If you’re moving files from one drive from another or over a network, consider copying them and removing the original after verifying the copy was successful.

When you’re working on the Linux command line, you don’t have a trash/recycle bin to recover accidentally deleted files – when they’re gone, they’re gone. If your file move operation fails for some reason, you may lose those files, so copying them instead and making sure they have transferred successfully will mitigate this.

You should also back up your files regularly to protect yourself from data loss.

View the original article from LinuxScrew here: Move Files With the mv Command in Linux, With Examples

]]>
https://www.linuxscrew.com/linux-move-file-mv/feed 0