date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,396,455,789,000
I love the nano feature that enables you to open multiple files at once and the fact that switching between them is very easy: nano file1 file2 etc. However, when I try to open a new file while working on one with ^R, it just inserts the whole fine within the file I was working on after I enter it. What I want to kno...
The M-F key combination must be used after first pressing ^R. Unless you first press ^R, the M-F command is tied to "Invoke a program to format/arrange/manipulate the buffer". After pressing ^R, you'll see M-F at the bottom of the screen with the description "New Buffer". So, to open a file in a new buffer in the nano...
Nano: how to just open a new file buffer inside of nano without altering the current one?
1,396,455,789,000
I am currently writing a small setup script for a Linux application that needs the user to edit a configuration file before the application is started. I've chosen to make the script simply open the configuration file in Nano, and resume the script afterwards. I do, however, need to detect whether the user saved the c...
You can use the stat command to check the file's modification time before and after nano. Something like: oldtime=`stat -c %Y "$filename"` nano "$filename" if [[ `stat -c %Y "$filename"` -gt $oldtime ]] ; then echo $filename has been modified fi Of course, this won't detect whether nano modified the file, or some...
How do I detect whether changes in nano were discarded or saved?
1,396,455,789,000
The nano editor by default displays only the filename being edited, but not its full path. This can be a problem, if I need to edit old vs new versions of files by the same name. Does anyone know of a way to toggle or change this behaviour to display a full path? Or is there no way short of figuring out where this hap...
man nano say's nothing about files' paths. /etc/nanorc nano configuration file also gives no such option. But if you want nano to display filename's full path, use full path during file's opening: nano /home/user/test/test.sh will show it the next way:
Display full path in title bar of nano editor
1,396,455,789,000
In a text file I need to comment out all lines by adding a ; as the first character of each line. What is a good way to do this? I thought of Vim's visual block mode, but I couldn't find a "select all" option and marking several hundred lines manually also isn't great. Any idea? I have nano, vi and vim at hand, I woul...
In Vim: gg0<ctrl-v>GI;<Esc>
How to comment all lines in a text file?
1,396,455,789,000
I recently installed Debian for CLI purposes. I am looking to install CLI packages, I want to know how to search for packages (CLI packages such as nano)?
To find CLI packages in Debian, you can look for packages tagged as interface::command-line, either using the tag search engine, or on your system by installing debtags and running debtags search interface::command-line Both approaches have options to refine the search. See the Debtags wiki page for more details. Thi...
How to search for Debian CLI packages?
1,396,455,789,000
I'd like to rebind the alt-left and alt-right keybindings in nano, can't seem to get it to work. I'm on ubuntu 16.04 my ~/.nanorc file: bind M-right nextword main bind M-left prevword main version info: GNU nano, version 2.5.3 (C) 1999..2016 Free Software Foundation, Inc. Email: [email protected] Web: http://www.nano...
If you see messages like [ backup files enabled ] when you try those shortcuts, it means they are producing Alt+B and Alt+F escape sequences. So you can just rebind those like so: unbind M-B all bind M-B prevword main unbind M-F all bind M-F nextword main See this bug report thread for more info.
Re-bind alt left/right in nano
1,396,455,789,000
I am looking for a keyboard shortcut to show the line numbers in nano editor when navigating up and and down within the file. I have seen in multiple posts about CTRL+C but this doesn't automatically refresh the line number while navigating. I remember that in the past I have used such shortcut in Linux terminal and i...
You can enable and disable the lines number for each individual line instead through: ALT + # see the help (Open nano then type Ctrl + G ): M-# Line numbering enable/disable Note that you can also enable line-numbering from the command-line too, using the argument -l, for example: $ nano -l somefile.txt ...
How to constantly show line number when navigating in nano?
1,396,455,789,000
I want to compile Nano from source for my friend. I have successfully compiled it on all of my computers and he's having Linux Mint 18.1 too. I don't know why; or better said I don't know what is missing in his system for UTF-8 support as per this configuration message: *** Insufficient UTF-8 support was detected in ...
It looks like you need to install libncursesw5-dev and/or libslang2-dev; that’s what’s missing according to the config log.
Compiling Nano with UTF-8 support on one computer failed
1,396,455,789,000
When justifying paragraphs, nano by default justifies into the number of columns in the screen. How can I force it to justify to a different number of columns (e.g. 80 characters)?
To set the number of characters in a justified line, just use the set fill configuration in ~/.nanorc: set fill 80 If you need a different size for only one file, you can use the -r flag: nano -r 60 myfile.txt In this case, however, the lines will be justifined while you are typing (which my not be always convenient...
How to set up the numer of columns on a justified paragraph in nano
1,396,455,789,000
In my folder I have a bunch of .cpp files. I use nano for editing my files. Is there a way for me to be able to write a single command and open all the .cpp files in different tabs? If I do nano *.cpp, the next file opens after I close the current one and that isn't the desired behavior. The desired behavior is that a...
Based On details in The comments it seems that you are running from a windows machine using putty. Due to limitations with the putty connection, You would need x forwarding to use a native terminal to have multiple tabs (as your putty terminal each tab is a separate connection, controlled by windows rather than being ...
Open files in new tab for nano
1,396,455,789,000
I've been configuring nano with the hopes of giving it the same keybindings as emacs, so that I can use nano for quick edits and emacs when I'm working on actual projects. However, I've run into a small problem: nano does not seem to want to let me reassign the ^/ key combination (to undo). Does anyone know how/if thi...
In most terminals (a side-effect of the way ASCII is encoded), ^/ is the same as ^_ (control_). The help-screen for nano on my Debian 7 machine shows that as Go to line and column number. M-/ is harder, since there is no standard for this. However, nano uses the assumption that the meta keys simply have an escape ch...
Is it possible to bind ^/ and M-/ in nano
1,629,713,616,000
Can Nano save the current position of the cursor at exit and, when you reopen the file, restore the old cursor position, like vim does?
On Ubuntu 2018. In ~/.nanorc put: set positionlog Just as a tip, I also have these: set tabsize 4 set tabstospaces set autoindent set smooth
Nano: Remember cursor position at start
1,629,713,616,000
Is it possible to sort a selected area of text alphabetically using the nano editor? ( similar to the F10 in xed ) I use Linux Mint 20 , nano 4.8 Thank you
Nano cannot do that. The best way to get this done is by learning the basics of file manipulation with the command line to chop the file in pieces, sort the piece you want to sort and put everything back together. If you want to have a editor that can do everything, even run shell scripts on your file from within the ...
Sorting lines in nano?
1,629,713,616,000
I am trying to compile my favorite nano command-line text editor with some of the options. Actually, most of the options in order to enable all features. First, I go to Downloads directory and download the tarball: cd Downloads wget --continue https://www.nano-editor.org/dist/v2.8/nano-2.8.0.tar.xz Then, I verify i...
Nano doesn't store the compiled options as provided on the ./configure command-line, it reconstructs them based on detected features and the requested target ("tiny" Nano or normal Nano). For tiny Nano, it reports enabled options, since they add to the default; for normal Nano, it reports disabled options, since they ...
Compiling Nano editor with options
1,629,713,616,000
When I use PuTTY to connect to a specific Linux server via the SSH protocol, and I try to edit a file using the nano editor, the "enter" does not update the display. When I press enter to insert another line break, the following lines do not move down. However, if I save the file and re-open it, the new line breaks ...
I found the problem by comparing my saved session in PuTTY for the "problem" server to one for a "working" server. Under the terminal emulation options, I had "DEC Origin Mode initially on" checked. Unchecking this option solved the problem.
Nano editor - display not updating with PuTTY
1,629,713,616,000
I am using the OS X Terminal (I know, not Linux or Unix, but hopefully that's irrelevant here) for a number of operations, and commonly use nano to quickly edit files. In doing so I often resize the Terminal window, and the nano interface resizes accordingly to fit the window. This is great, allows me to see my work b...
Terminal resize generates a SIGWINCH signal that is sent to the foreground applications. Said applications are supposed to catch that signal (provided they care about terminal size to begin with), and adjust accordingly. What seems to be going on when you resize the terminal while nano is running from ipython is tha...
Resizing the terminal window for ipython command prompt
1,629,713,616,000
In my latex.nanorc file, I have the following instructions: syntax "LaTeX" "\.(la)?tex$" linter lacheck However, when I press the keyboard shortcut to run the linter, I get an error message La commande « lacheck » n'a produit aucune ligne analysable (i.e The 'lacheck' command did not produce any analysable lines in ...
There's a de facto standard format for compiler or linter error messages, which is the same format as grep -n: FILE_NAME:LINE_NUMBER:MESSAGE. Experimentally, nano supports that. I haven't researched if it supports any other format, but in any case it doesn't support lacheck's format. You can define a wrapper to the la...
Which linters are supported by nano?
1,629,713,616,000
How can I configure ~/.emacs so that I indent how nano does by default? Uses a tab character instead of 5 spaces I can add as many tabs to a line as I please
I added the following to ~/.emacs: (setq-default indent-tabs-mode t) (setq backward-delete-char-untabify-method nil) (setq indent-tabs-mode t) (defun my-insert-tab-char () "Insert a tab char. (ASCII 9, \t)" (interactive) (insert "\t")) (global-set-key (kbd "TAB") 'my-insert-tab-char) ; same as Ctrl+i
How to make 'emacs' indent with tabs exactly how 'nano' does...?
1,629,713,616,000
I was wondering how could I make lines commented with a # highlighted in a different colour in nano? I saw this question on askubuntu that shows how to syntax highlight for different languages. However this is overkill for just highlighting comments.
Syntax highlighting tends to be language specific. However, if you want to do it for all files, you can simply create a very very simple language definition. I took the Perl syntax style (which treats lines starting with # as comments) from /usr/share/nano/perl.nanorc and adapted it to: syntax "All" "." color green "^...
How to auto highlight comments in nano?
1,629,713,616,000
It seems to ignore newline characters in "parsed" view. In raw view everything is fine. Same thing happens in nano "justified" mode. a) parsed text file b) same file in raw mode c) vi with :set list d) same file in parsed mode when the name is changed to "tt" Can anyone explain this?
The problem is not the ., but the .1 . This extension is used for man pages - and so the viewer tries to interpret this as a man page. Edit: this is controlled by the file /etc/mc/mc.ext - you'll find a # Manual page regex/(([^0-9]|^[^\.]*)\.([1-9][A-Za-z]*|[ln])|\.man)$ Open=/usr/lib/mc/ext.d/text.sh open man...
mc (midnight commander) view (F3) strange behavior when there is a "." in the filename
1,629,713,616,000
I'd like the line numbers to show automatically whenever I use nano. I've seen the set const command in ~/.nanorc but I want to see the line numbers in the column to the left, activated by meta-# within nano. Is there a way to automatically use meta-# whenever I use nano without having to do it myself? Thanks
I don't have the latest version but browsing through the sources online shows that M-# is setting an option called linenumbers, and indeed this is described in the new man page for nanorc: set linenumbers Display line numbers to the left of the text area. There is also a command line -l or --linenumbers optio...
Use keyboard shortcut automatically in nano? [duplicate]
1,629,713,616,000
In normal mode, I can use mouse left button to copy and right button to paste, but not with mouse mode: -m --mouse Enable the use of the mouse Is copy/paste still possible with mouse mode?
The Issue at it's simplest is that your terminal emulator has two ways to deal with the mouse (besides ignore it). They are do something intelligent with the mouse since the program being run doesn't know what to do with it, or let the application deal with it. Most terminal emulators do both and chose between the two...
How to copy and paste in nano editor with mouse enabled? [duplicate]
1,629,713,616,000
I have a professor who stores homework assignments in many files spread across different sub-directories in a lecture folder with the header "TODO:" I'd like to output all these todo's to a single text file in nano instead of navigating from one assignment file to another. I tried to make an alias for this command, s...
I figured it out, thanks for the pointers guys. The problem here was that grep was recursively searching for "TODO:" in the todo.txt file and then writing those results back to the todo.txt file. When I opened todo.txt it was filled with the same text looped over and over again. Evidently, I should have used the --exc...
Grep alias piped to nano. Nothing happens when command is issued
1,629,713,616,000
Can you help with this regex in my sourceslist.nanorc ? Regex: cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/ Error: Bad regex "cdrom:\[[a-zA-Z0-9\._-\(\) ]+\]/": Invalid range end Thank you.
The problem is likely to be the placement of the - sign in your character list. You have already used the fact that ranges of characters can be expressed by [start-end], as in [a-z] being shorthand for [abcdefghijkl...xyz] (although see the caveat below). That means that the - is a special character, and if it occurs ...
Bad regex : Invalid range end
1,629,713,616,000
I want all users of nano to have tabsize 4 instead of the default 8. What is the best way to achieve this? I would prefer a file that overrides /etc/nanorc at the system level so I don't have to maintain separate user nanorc's for this purpose. In the simple case, my override would only need to contain: set tabsize 4 ...
So /etc/nanorc.pacnew is the new rc file that came with the new distribution upgrade? How about sed '/tabsize/ {s/^# *//; s/[0-9]*$/4/}' /etc/nanorc.pacnew > /etc/nanorc , then? Another possible trick might be to have a symbolic link ~/.nanorc in every user's home dir pointing to a central file with the relevant com...
How to override /etc/nanorc systemwide?
1,629,713,616,000
I tried the following recommended approaches unsuccessfully to toggle softwrap in nano on MacOS Catalina: I can't do Alt+S as in the manual, it gives ß on my keyboard. Esc-S gives "Smooth scrolling enabled" Esc-$ gives "Unknown command" What can I do?
The default nano on macOS is release 2.0.6. Soft line wrapping, enabled via the -a command line option or via Esc+$ inside the editor, was introduced in release 2.2. To install a more recent release of the editor on macOS, use e.g. Homebrew: brew install nano This would (currently) install nano release 4.9.2, which a...
How to toggle nano softwrap on mac
1,629,713,616,000
I encrypted a text file in terminal using "gpg -c filename" and got "filename.txt.gpg" created in my file manager. I deleted the original unencrypted file. Now I want to decrypt it in Nano so I can continue working on it. If, in a terminal, I do "gpg -d filename.txt.gpg", the file opens in terminal where I can read i...
gpg -d just prints the file to standard output, but you can redirect the output to a file instead: gpg -d filename.txt.gpg > filename.txt. Or use the -o outputfilename option. Also, you can just run gpg filename.txt.gpg, which cause gpg to guess what you want, and in that case it decrypts the file to filename.txt (dro...
How decrypt a file in nano text editor?
1,629,713,616,000
I wanted to make Nano have more common shortcuts (i.e. Ctrl-F for search, Ctrl-H for replace, etc) and edited the nanorc file to add: bind ^F whereis all bind ^H replace all bind ^M mark all ... To my astonishment, pressing Backspace activates the Replace function and pressing Enter activates Mark. Then i realized th...
The virtual terminal you are using nano on is modelled after the physical serial terminals of past decades. By convention, these terminals produced ASCII control codes when a letter key or one of the keys labelled @, [, \, ], ^, _ were pressed together with the Ctrl key. The control code emitted has the ASCII code of ...
Nano editor: are Ctrl keybindings actually bitmasked?
1,629,713,616,000
Is there a SIMPLE way to format nano file text? My code is getting pretty messy, so it MAY help to format it.
There is also clang-format command
nano text file formatter? [closed]
1,629,713,616,000
Instead of using sudo find / -name "supervisor" I ran sudo nano / -name "supervisor" by mistake, which looked like it opened a blank nano file before I hit CRTL-X... $ sudo nano / -name "supervisor" Use "fg" to return to nano. [1]+ Stopped sudo nano / -name "supervisor" The operating system is Ubunt...
The command would have started the nano editor and instructed it to edit the root directory. nano would have complained with a [ "/" is a directory ] message. No files would have been changed.
Mistyped command: sudo nano / -name "supervisor"
1,629,713,616,000
Extremely simple question. In the attached image the majority of options seem to entail typing ^ and another character at the same time. The problem is that to type ^ I need to press Shift + 6, at which point I am actually typing ^ before I have a chance to press the second character, e.g. ^T.
^O is a representation of a character, the one usually sent by your terminal upon pressing Ctrl+o, not a key. In terminals, applications get input by reading a stream of bytes from a /dev/tty* or /dev/pt* device file, not by handling keyboard events, and those bytes are the ones that are sent there by your terminal ...
How to handle caret + character options in GNU nano editor in Ubuntu
1,629,713,616,000
How can I change the actual editor theme in .nanorc, I am not speaking about the syntax highlighting but editor elements such as titlebar or line numbers color/background color? For instance, I would like to set the title bar and line numbers background to black/transparent, and the font color to white.
Edit the nanorc file, and add the following lines: set titlecolor COLOR_1,COLOR_2 # COLOR_1 is the text, COLOR_2 is the background. Supported colors are white, black, blue, green, red, cyan, yellow, magenta set numbercolor COLOR_1,COLOR_2 # same as above
nano change line numbers color
1,629,713,616,000
I was ssh'ing into a Raspberry Pi running Raspbian, editing a file with nano, when I lost my internet connection (by leaving the WiFi zone). After reconnecting an hour later, I found that the pi had kicked me out, but after logging back in, I saw that it did not stop the task. When I reopened nano, it told me that the...
In the comments, @JeffSchaller noted that a terminated nano process saves the unwritten file in file_path.extension.save. If it is there, which it was for me, it is a simple matter of mving the file into its original name.
How to exit nano from a different terminal?
1,629,713,616,000
I have compiled GNU/Nano editor myself and I wish to add it to the system editors list. which nano Tells me the following location: /usr/local/bin/nano So it should be something like: sudo update-alternatives --install /usr/bin/editor editor /usr/local/bin/nano 1 But I need to put pieces together. Could you help ...
Check out what the package does in its postinst: update-alternatives --install /usr/bin/editor editor /bin/nano 40 \ --slave /usr/share/man/man1/editor.1.gz editor.1.gz \ /usr/share/man/man1/nano.1.gz This installs /bin/nano as an alternative for /usr/bin/editor (the alternative named editor, so /etc/alternatives...
Compiled GNU/Nano: How to add to system editors list
1,629,713,616,000
When I trying this command modinfo fbtft I get this result: modinfo: ERROR: Module fbtft not found. But when I do checking, I have fbtft file in this location : /lib/modules/3.18.1+/kernel/drivers/video/fbdev/fbtft Do I have kernel support for fbtft or not? if not, how to add it? My system is an arm-based computer(n...
/lib/modules/3.18.1+/kernel/drivers/video/fbdev/fbtft is a directory. modinfo fbtft or modprobe fbtft looks for a file called fbtft.ko, which should be in that directory. The fbtft driver can either be compiled as a module or linked into the main kernel binary. If it's in the main kernel binary then there won't be a f...
Do I have kernel support for fbtft?
1,629,713,616,000
I needed to be able to set the cursor using mouse when editing text via nano over putty. I have already set the below in ~/.nanorc: set mouse If I start nano file just like that then it works, but if I require elevated rights and sudo nano file then it's not. How on earth is that possible? I suppose in that case nano...
I suppose in that case nano is using another .nanorc? Yep. When you run sudo nano file, HOME environment variable is set to /root, so nano looks for .nanorc there. Just add the setting into /root/.nanorc, and you should be fine.
Setting nano cursor using mouse via putty doesn't work if sudo
1,629,713,616,000
In nano v8.0 there's an option to send selection to X clipboard in the nanorc: "{execute}|xsel -ib{enter}{undo}" which does perfectly. I tried using xclip utility instead: "{execute}|xclip -sel c{enter}{undo}" The result was an infinite execution [ Executing... ], insensitive to interaction until hit ^C. After the c...
Why? From this answer: Selections in X work by two X clients cooperating: One X client claims it has a selection (primary, secondary, clipboard), and another X client that wants to paste the selection contacts the first client to receive it. In your case the original xclip exits but its child survives to claim it ha...
nano command execution stuck
1,629,713,616,000
I'm having a weird issue under debian 11 with resolvconf package. No matter what kind of configuration I throw in, the /etc/resolv.conf file created by resolvconf service is kinda corrupt. Dig says: dig: parse of /etc/resolv.conf failed If I use an editor like nano to add just a space or newline or even nothing like ...
I compared the files visually, and nothing was different. However in just one point aside the permission error @A.B suggested me I found also that there was a line with \r\n instead of \n in my head file. Editing and saving the file with nano fixed automatically the newline error but with the diff tool everything was ...
resolvconf package create corrupt /etc/resolv.conf file
1,629,713,616,000
When I copy and paste text from the clipboard, the code looks like [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "heroku"] instead of [core] repositoryformatversion = 0 filemode = true bare = false ...
If you don't want autoindent enabled, you should not set autoindent, as that enables it. Instead, use unset autoindent in your .nanorc. For more information, see man nanorc You can also toggle autoindent with ALT+I (see CTRL+G for all shortcuts).
Why does nano indent pasted text or code improperly?
1,629,713,616,000
I am using Debian GNU/Linux. Are there any options or extensions to vim that give me the possibility to display a cheat sheet in vim as shown in Nano?
I'm not aware of any way to do this. The cheatsheet that's used in Nano is built into the source code, and the editor it's modeled after, Pico, has one as well. Vim, however, doesn't have such an option as far as I'm aware. There are many more commands that are commonly used in Vim than in Nano. My version of Nano ...
Is it possible to show a vim cheatsheet like in Nano at the bottom of the page?
1,629,713,616,000
Here are my personal aliases for editing root owned files: # CLI superuser nano; compiled; version 2.8.0 function sunano { export SUDO_EDITOR='/usr/local/bin/nano' sudoedit "$@" } # GUI superuser xed; packaged; version 1.2.2 function suxed { export SUDO_EDITOR='/usr/bin/xed' sudoedit "$@" } # GUI...
The issue here is that sudoedit copies the file to a temporary file before opening it in the editor. When the file has an extension, the temporary file is created with the same extension, and filename-based syntax highlighting modes are selected appropriately (e.g. for C files). When the file doesn’t have an extension...
Nano through Sudoedit = No colors
1,629,713,616,000
How to input text into a new text file using nano from command line? I would like the same as with the following, but using nano: echo 'Hello, world.' >foo.txt Result: nano is not capable of handling non-interactive text input. echo is available in every Linux/Unix system, while nano is not installed by default in ...
You can use a here document but with this way it is not possible to provide a special output document. $ cat | nano <<-EOF one two three EOF Received SIGHUP or SIGTERM Buffer written to nano.save This behaviour is mentioned in the man page under notes In some cases nano will try to dump the buffer into an emerg...
How to input text into a new text file using nano from command line?
1,629,713,616,000
I have a file which contain ₹ (rupees) sign. but with nano Update: Is there something wrong with my locale? :~$ cat /etc/default/locale LANG="en_GB.UTF-8" LANGUAGE="en_GB:en" LC_NUMERIC="en_GB.UTF-8" LC_TIME="en_IN.UTF-8" LC_MONETARY="en_IN.UTF-8" LC_PAPER="en_GB.UTF-8" LC_IDENTIFICATION="en_GB.UTF-8" LC_NAME="en_GB...
It seems that v2.4 (obviously, v2.2 too) has either bug or cannot display some of the unicode characters. v2.5 can display rupee sign
GNU nano 2.2.6 won't show ₹ (rupees sign)
1,629,713,616,000
I'm trying to set my color syntax highlighting in nano, but it doesn't work as expected. One system everything works. This is an Fedora 21 laptop. Two systems everything I've tried except man something works. This is an Fedora 21 desktop and an Fedora 21 vm in VirtualBox. One system only one file I've tried works(ope...
I since found that there is a bug in nano < 2.7.4-1 nano: /etc/nanorc is ignored, if ~/.nanorc exists Latest from the bug report: I just made the dist-upgrade to Debian 9.0, which included an update of package nano to version 2.7.4-1 and the problem vanished, the bug is solved in 2.7.4-1. The bug report: bug
Color syntax highlighting working on one system but not the others. Same nanorc file
1,374,841,330,000
When I pressed Ctrl+T in Nano it gave the error Spell checking Failed: Error invoking Spell. So I followed this answer and added set speller "aspell -x -c" to my ~/.nanorc and the spell check is now working perfectly. But what did this command do? What was causing the error? And why did this nanorc command fix it?
From http://www.nano-editor.org/dist/v2.2/nano.html: -s <prog>, --speller=<prog> Invoke the given program as the spell checker. By default, nano uses the command specified in the SPELL environment variable, or, if SPELL is not set, its own interactive spell checker that requires the spell program to be installed on ...
What does the command set speller "aspell -x -c" in nanorc do?
1,374,841,330,000
I am not sure if this can be done or not. I have two different .nanorc files (.nanorc1 and .nanorc2). Each file has different settings. For example one has tabs set to 9 spaces and the other has tabs set to 4 spaces. Each .nanorc file is used for different files that require different settings. Is there a cli opt...
Since man nano does not show a way to specify anything other than ~/.nanorc, you'll have to keep master copies of each variant, and cp it to ~/.nanorc before each edit. For example, if you have $HOME/nanorc/nanorcA and$HOME/nanorc/nanorcB , and in $HOME/.bashrc: alias nanoA="cp $HOME/nanorc/nanorcA $HOME/.nanorc;nano...
Using multiple .nanorc files
1,374,841,330,000
How can I combine the "find" command with the "nano" command? For example, find . -name "helloworld.py" | nano How to open that file (first out of several lets say) after it is found using "nano" (without using a function but a single line of chained commands)?
To edit the first file only, find . -name helloworld.py -exec nano {} \; -quit This looks for files named helloworld.py, and for each such file found, runs nano /path/to/helloworld.py, and then quits (which means that only the first file will be processed). To edit all the matching files, find . -name helloworld.py -...
How to combine the commands "find" and "nano"
1,374,841,330,000
I haven't been able to get crontab to execute any of my scripts on start-up. I want to know why it doesn't work. Below is an example of me trying to use it, and I've tried to provide as much troubleshooting information as I can. $crontab -l no crontab for server $crontab -e #I scroll down to the bottom of the file an...
You have to use Ctrl+x to exit nano and install new crontab. Ctrl+z will just stop/send to background nano without installing new crontab. See attached screenshot:
Using nano to edit a crontab [closed]
1,374,841,330,000
So i am pretty new to linux and i am learning basic commands. I am also very interested to know how things work under the hood, so sometime after i learned both the cat and nano commands, i tried using them on an image, and all these weird symbols appeared (linux mint): I also tried it on kali, i got the same thing, ...
All files are made of 1s and 0s, each of which is called a bit. A "byte" is 8 bits. For 8 bits, there are 256 possible combinations of 1s and 0s. The data in plain text files, which is what nano is meant to edit (and terminals expect to output with cat) is divided into bytes. Typically, each character in the file make...
What are the weird characters from an image file?
1,374,841,330,000
In Terminal I su - admin while in my user account to brew update, modify .bashrc, etc. I have noticed that when in my user session changing the size of the window while running nano doesn't scramble the text at all. The window resizes perfectly. However, after opening a new Terminal window, running su - admin, then na...
Using login on OS X is a workaround for this issue. $ login login: your username password: your password Last login: Day Month Date HH:MM:SS on ttys000 $ whoami your username Thanks to user grg on Apple Stack Exchange
How to solve the issue where nano screen text is scrambled when using su - admin
1,374,841,330,000
I'm looking to write a bash script that recursively searches directories, find a particular string, then opens to that string in that particular file. I call this function exert because it takes away the exertion of finding a particular variable in my software. For e.g. if my website uses a phrase like "I like big cat...
The problem arises from using grep --color=always as the first command. Apparently, bash keeps track of color for its shell using the control characters I listed above. So, ./^[[35m^[[Kapp.vue^[[m^[[K^[[36m^[[K is actually telling bash, "this string has text app.vue, with purple text coloring". Nano, however, is colo...
Bash script's array element can't act as a filename for nano, some kind of encoding error
1,374,841,330,000
To edit the root crontab in Debian I do for example sudo crontab -e. To exit from the preferred text editor (Nano), I do CTLR+X. So far so good, but what if I want that each time I exit crontab, a text will be echoed into the console (into "stdout"). The purpose is to echo a reminder message like: If you haven't alre...
You can assign the $EDITOR variable a script which first calls an editor and then produces the output: #! /bin/bash vim "$1" echo "foo bar baz" and use this call EDITOR=/path/to/script.sh crontab -e
Echo something to console each time you quit crontab
1,374,841,330,000
I have a .txt file from my Mac that when I send it over to my Raspberry Pi running Raspbian and open it in nano it converts weirdly. Example: Text file in Mac OSX: http://welcome.hp.com/country/us/en/prodserv/servers.html http://www8.hp.com/us/en/products/data-storage/overview.html Text file in Raspbian: Servers & ...
sed -i 's/\r/\n/g' thefile.txt "classic" macos used \r as the end-of-line character. *nix uses \n
.txt File from Mac not converting properly
1,374,841,330,000
I've been playing with the keyboard mapping in the .nanorc file some today, and you can map the F keys like...bind F3 cancel all, however, i haven't had any luck with trying find how nano recognizes the escape key. I've already tried Esc, esc, nano keeps giving me an error message. Is there a way to bind/map the escap...
You can not do it. The keys which could be mapped are described here: https://www.nano-editor.org/dist/latest/nano.html#Rebinding-Keys It also has a statement: Rebinding ^[ (Esc) is not possible, because its keycode is the starter byte of Meta keystrokes and escape sequences.
Nano: can the escape key be mapped?
1,374,841,330,000
The last two array expansions don't get proper highlighting: This is the setting in sh.nanorc that defines it: # More complicated variable names; handles braces and replacements and arrays. color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])?(([#%/]|:?...
Regexes like that are a bit of a write-only language, but I think the (\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])? in the middle catches the array indexes. It also doesn't recognize [*] as an index. It's hard to fix that properly, as array indexes can be almost arbitrary shell "expressions". In an integer-indexed ...
nano highlighting fails in matching shell array brackets
1,374,841,330,000
The key combination Alt + 6 for copy in nano does not work in tilix Does anyone know how to fix this? I had a look through all the key commands, but did not find any entry for Alt + 6 being already in use.
In Tilix version: 1.9.6 you can manually change and set key commands. Disable Alt + 6 which is set to switch to terminal Nr.6. by default.
The key combination Alt + 6 for copy in nano does not work in GNOME terminal emulator Tilix
1,374,841,330,000
To make the question better understood -> I currently have to run nano with sudo when i just want to run nano to edit a file. So while I was fiddling with Ubuntu 20.04 in a VM I had everything more or less working in a way that I felt comfortable putting it onto an old laptop. In the VM I could just run ~$ nano , writ...
Those files don't belong to you - they belong to root: -rw-r--r-- 1 root root 1030 Sep 23 23:59 'Mounting a device' ^owner If that's not correct you need to change the ownership back to yourself. To change the directory and its files you can do this Change to the ~/Documents directory cd ~/Documents ...
I need to run ~$ sudo nano in order write and save a file and can't do so with just the nano command. How do I change this?
1,374,841,330,000
I'm using: Debian bullseye with its MATE desktop environment MATE caja 1.22.1 MATE Terminal 1.22.1 GNU nano, version 4.3 In nano, Redo is mapped to Meta+E. In Keyboard Preferences I have selected "German German (no dead keys)" and in the Keyboard Layout Options under Alt/Win key behaviour, I have selected Meta is ma...
Esc+E works. According to the nano online help: Meta-key sequences are notated with 'M-' and can be entered using either the Alt, Cmd, or Esc key, depending on your keyboard setup.
How to use nano's Redo shortcut (Meta+E) in MATE terminal
1,374,841,330,000
I have been trying to bind the shortcut CTRL-[ to the unindent function, but it seems like that if you type in bind ^[ unindent main (CTRL-[) into nanorc, the text will be still formatted in red, not the usual green which tells you that the binding would work. I tried changing it to bind M-[ unindent main (ALT-[), but...
You can't. Terminals send characters, not keys. (See How do keyboard input and text output work? for more details.) But not all keys have a corresponding character. When you press a key or key chord that doesn't have a corresponding character, the terminal sends a sequence of characters that represents it, or in a few...
How can you bind ^[ or M-[ shortcut to an action in nano?
1,567,011,012,000
I am trying to apply below nftables rule which I adopted from this guide: nft add rule filter INPUT tcp flags != syn counter drop somehow this is ending up with: Error: Could not process rule: No such file or directory Can anyone spot what exactly I might be missing in this rule?
You're probably missing your table or chain. nft list ruleset will give you what you are working with. If it prints out nothing, you're missing both. nft add table ip filter # create table nft add chain ip filter INPUT { type filter hook input priority 0 \; } # create chain Then you should be able to add your rule t...
nftables rule: No such file or directory error
1,567,011,012,000
When configuring a chain in nftables, one has to provide a priority value. Almost all online examples set a piority of 0; sometimes, a value of 100 gets used with certain hooks (output, postrouting). The nftables wiki has to say: The priority can be used to order the chains or to put them before or after some Netfilt...
UPDATE: iptables-nft (rather than iptables-legacy) is using the nftables kernel API and in addition a compatibility layer to reuse xtables kernel modules (those described in iptables-extensions) when there's no native nftables translation available. It should be treated as nftables in most regards, except for this que...
When and how to use chain priorities in nftables
1,567,011,012,000
On Netfilter, you have the option --set-mark for packets that pass through the mangle table. The majority of tutorials and examples over the Internet, say that this just adds a mark on the packet, like this, but there's no additional detail of what mark is set and where it resides on the packet: iptables -A PREROUTING...
The mark is a 32 bits integer value attached to a network packet. Some network parts interacting with it (see below) can do bitwise operations on this value, it can then be interpreted between one single 32 bits value up to a collection of 32 flags, or a mix of flags and smaller values, depending on how one chooses to...
How --set-mark option works on Netfilter (IPTABLES)?
1,567,011,012,000
How can i do this in a single line? tcp dport 53 counter accept comment "accept DNS" udp dport 53 counter accept comment "accept DNS"
With a recent enough nftables, you can just write: meta l4proto {tcp, udp} th dport 53 counter accept comment "accept DNS" Actually, you can do even better: set okports { type inet_proto . inet_service counter elements = { tcp . 22, # SSH tcp . 53, # DNS (TCP) udp . 53 # DNS (UDP) } And then: ...
How to match both UDP and TCP for given ports in one line with nftables
1,567,011,012,000
Why does SNAT(modifies source IP and/or ports) happen in nat table POSTROUTING chain, i.e after routing? And why does DNAT(modifies destination IP ant/or ports) happen in PREROUTING chain? I guess latter is because there might be multiple NICs in PC with different private networks and PC does not know how to route pac...
Usually the main criterion for SNAT is "traffic that's going out a given interface" (i.e. -o eth0). What interface a packet will go out is determined by routing, so to apply that criterion you need to run it in a POSTROUTING context. DNAT rewrites the destination address of a packet, meaning it can affect where a pack...
Why does SNAT happen in POSTROUTING chain and DNAT in PREROUTING chain?
1,567,011,012,000
Given a host that is in an unknown state of configuration, I would like to know if there is an effective way of non-interactively determining if the firewall rule set in place is managed by iptables or nftables. Sounds pretty simple and I've given this quite a bit of thought, but haven't come back with a meaningful an...
A variant of this problem was addressed recently in Kubernetes, so it’s worth looking at what was done there. (The variant is whether to use iptables-legacy or iptables-nft and their IPv6 variants to drive the host’s rules.) The approach taken in Kubernetes is to look at the number of lines output by the respective “s...
Check whether iptables or nftables are in use
1,567,011,012,000
I would like to know the exact position of the following device in the packet flow for ingress traffic shaping: IFB: Intermediate Functional Block I would like to better understand how packets are flowing to this device and exactly when this happens to understand what methods for filtering / classification can be us...
I think I finally understood how redirecting ingress to IFB is working: +-------+ +------+ +------+ |ingress| |egress| +---------+ |egress| |qdisc +--->qdisc +--->netfilter+--->qdisc | |eth1 | |ifb1 | +---------+ |eth1 | +-------+ +------+ +------+ My initial assum...
How is the IFB device positioned in the packet flow of the Linux kernel
1,567,011,012,000
According to tcpdump, my server receives the following TCP packet: 12:52:29.603233 00:19:e2:9e:df:f0 00:16:3e:6a:25:3f, ethertype IPv4 (0x0800), length 74: 10.10.10.65.38869 192.168.215.82.22: Flags [S], seq 567054335, win 5840, options [mss 1460,sackOK,TS val 2096335479 ecr 0,nop,wscale 0], length 0 As seen above,...
However, are there any other clever tools/methods to see if process listening on TCP port receives a message? You can use strace with -e trace=network. This is what it prints on accepting a TCP connection, receiving an HTTP request, sending an HTTP response and closing the connection: $ strace -v -f -e trace=networ...
Is there a way to see if process listening on TCP port receives a message?
1,567,011,012,000
Setup: VM1 --- Bridge -- VM2 VM1 and 2 are on same subnet. Bridge has 2 interfaces added to brctl bridge. When I block VM2 ip using uptables -A FORWARD -s (VM1 ip) -j DENY it doesn't work. I understand the packet never goes to network layer but this says "all iptables chains will be traversed while the IP packet is in...
Linux' bridge filter framework has available mechanisms where the layer 2 bridge code can do an upcall to iptables (as well as arptables or ip6tables) and have filtering travel from layer 2 (bridged frames) through layer 3 (iptables with packets) and then back to layer 2. This is much beyond the use the BROUTING chain...
How does iptable work with linux bridge?
1,567,011,012,000
I'm using nfsen and I need to apply a filter to get specific ip range and I can't find the syntax. I searched in the doc of nfdump and tcpdump but nothing. For now the netflows captured provides from multiples address and the ip range I want to get (and only those address) is from 130.190.0.0 to 130.190.127.255 with a...
If you want a filter to capture on packets mathing 130.190.0.0/17: tcpdump net 130.190.0.0/17
tcpdump ip range
1,567,011,012,000
The L7-filter project appears to be 15 years old, requires kernel patches with no support for kernels past version 2.6, and most of the pattern files it has appear to have been written in 2003. Usually when there's a project that is that old, and that popular, there are new projects to replace it, but I can't find any...
You must be talking of (the former) project Application Layer Packet Classifier for Linux, which was implemented as patches, for the 2.4 and the 2.6 kernels. The major problem with this project, is that the technology which it proposed to control, quickly outpaced the usefulness and efficacy of the implementation. Th...
Is there a way to do layer 7 filtering in Linux?
1,567,011,012,000
I am going to use iptables for port forwarding to listen on requests from my LAN on port 8080 and answer with container at port 80, like this: iptables -t nat -A PREROUTING -p tcp -d 192.168.1.15 --dport 8080 -j DNAT --to 10.0.3.103:80 I am not sure if the rule is right (feel free to correct it), but the question is:...
There is a comment module for iptables which should do what you need. When adding a rule, one can add a comment like this: iptables -A INPUT -p icmp -j ACCEPT -m comment --comment "Allow incoming ICMP"
How to tag IPTABLES rules?
1,567,011,012,000
When it comes to packet filtering/management I never actually know what is going on inside the kernel. There are so many different tools that act on the packets, either from userspace (modifying kernel-space subsystems) or directly on kernel-space. Is there any place where each tool documents the interaction with othe...
Most folks I know who are working with the Linux network stack use the below diagram (which you can find on Wikipedia under CC BY-SA 3.0 license). As you can see, in addition to the netfilter hooks, it also documents XFRM processing points and some eBPF hook points. tc eBPF programs would be executed as part of the i...
How do packets flow through the kernel
1,567,011,012,000
I have an embedded Linux on some network device. Because this device is pretty important I have to make many network tests (I have a separate device for that). These tests include flooding my device with ARP packets (normal packets, malformed packets, packets with different size etc.) I read about different xx-tables ...
What xx-tables is the best to filter (limit, not drop) ARP packets? iptables iptables starts from IP layer: it's already too late to handle ARP. arptables While specialized in ARP, arptables lacks the necessary matches and/or targets to limit rather than just drop ARP packets. It can't be used for your purpose. ebta...
Best way to filter/limit ARP packets on embedded Linux
1,567,011,012,000
connlimit lets me limit the number of connections per client/service. How would I go about to combine such a rule with the IP sets available in more recent versions of the Linux kernel and netfilter?
Let's say we have an ipset named MYTESTSET, and that this ipset is of type hash:ip. It will store just ip adresses. Then match against your IPset and after match against connlimit match extension, with the parameters you want. iptables -A INPUT -p tcp -m set --match-set MYTESTSET src ...
How to combine connlimit with IP sets?
1,567,011,012,000
I just started learning about netfilter and I was trying to make a simple netfilter module, all the tutorials and HOW TOs register a hook function with nf_register_hook(), but I could not find one in linux kernels above 4.13-rc1. As far as I understand, the nf_register_hook() function used to call the _nf_register_hoo...
Use the following code: #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,13,0) nf_register_net_hook(&init_net, reg) #else nf_register_hook(reg) #endif Reference: init_net
nf_register_hook not found in linux kernel 4.13-rc2 and later
1,567,011,012,000
I have a wonderful ISP blocking all UDP traffic (except DNS to its own DNS servers). However, I want to use UDP for my VPN solution. I have root over both VPN endpoints, and both of them are using Linux. My idea is to simply overwrite the packet type field in my outgoing UDP packets to look as TCP, and doing the rever...
I doubt iptables alone will be enough, as TCP and UDP are fundamentally different protocols. You can forget setting up an IPsec VPN with such scenario (ISP blocking all UDP ports). Tunnel all the traffic via ICMP. (best old school solution I know of. Lots of organizations still do not filter out any kind of ICMP) see ...
How can I transform UDP to TCP with netfilter?
1,567,011,012,000
I'm looking to apply firewall rules on egress to control DHCP output from a Docker container. I don't want the DHCP container to share the host's network stack as adding CAP_NET_ADMIN effectively gives the container control of the network stack. I notice here that an egress hook was added to netfilter in kernel 5.7 (u...
Actually nftables's egress hook was added in kernel 5.16, and improved support (fwd) in 5.17. There were several attempts earlier, and one of them was NACK-ed at the same time it was initially committed, making it appear in Kernel Newbies for version 5.7, and apparently even nftables' wiki has it wrong by linking to K...
NFTables Egress Hook?
1,567,011,012,000
I am currently testing netfilter / nftables / nft. As a starting point, I have made a ruleset that drops nearly everything in and out, and have written the rules so that every dropped packet is logged. As always, and as it probably has to be, I don't understand the very first thing the machine tries to do and that I n...
This is a bug in Netfilter's ARP logs. There was a bug report about this problem. It was discovered that ARP didn't log using the correct data (it used data from link layer header instead of ARP's network layer). A patch was committed to fix this a few days later and appeared in kernel 5.19: netfilter: nf_log: incor...
What are ARP hardware type 37, opcode 21 and protocol type 0x90bd?
1,567,011,012,000
Current system: Distro: Ubuntu 20.04 kernel: 5.4.0-124-generic nft: nftables v0.9.3 (Topsy) I am new and learning nftables, Here is my nft ruleset currently: $sudo nft list ruleset ...
The wiki says what you tried is not yet implemented: You have to obtain the handle to delete a rule. The example is: $ sudo nft -a list table inet filter table inet filter { ... chain output { type filter hook output priority 0; ip daddr 192.168.1.1 counter packets 1 bytes 84 # hand...
How do I delete a specific element in a chain in nftables?
1,567,011,012,000
I use netfilter-persistent to manage a firewall. I would like to share a connection between two interfaces using masquerading (example, or another). When I run those operations by invoking iptables it works. But if I try to update firewall rules stored in /etc/iptables/rules.v4 adding such a line: -t nat -A POSTROUTI...
You're probably adding a rule intended for the nat table in the filter table block suitable for iptables-restore, and with inappropriate syntax. Until you know how to edit /etc/iptables/rules.v4 directly (by studying the output of iptables-save), you should do this instead: be careful, since the rule will be applied ...
Masquerade rule with netfilter-persistent
1,567,011,012,000
I observed that MASQUERADE target does not match on packets in the reply direction (in terms of netfilter conntrack). I've a single simple -t nat -A POSTROUTING -s 10.a.0.0/16 -d 10.b.0.0/16 -j MASQUERADE rule, nothing else besides of ACCEPT policies on all chains, and it seems that case 1) SYN packets of connection i...
The identity of a TCP connection is defined by a set of four things: the IP address of endpoint A the IP address of endpoint B the port number of endpoint A the port number of endpoint B The TCP protocol standard says that if any of these four things are changed, the packet must not be considered part of the same co...
in iptables, does MASQUERADE match only on NEW connections (SYN packets)?
1,567,011,012,000
I was reading the book Linux Firewalls - Attack Detection and Response (by M. Rash, No Starch Press, 1 Ed., Oct. 2007). In one of its chapter it discusses string matching using iptables. I was wondering: if string matching is still supported by Linux kernel and iptables/Netfilter if yes, can string matching search t...
Yes, the string extension is still supported (see also your local man iptables-extensions documentation). No, you can’t match against encrypted payloads — they’re still encrypted in the filtering layer...
Is iptables string matching still supported?
1,567,011,012,000
Reading in detail about iptables / netfilter here, when I read about the -o argument: "Indicates the interface through which the outgoing packets are sent through the INPUT, FORWARD, and PREROUTING chain." This seems to me to be wrong as they have written the same thing for the -i argument. It seems to me it sho...
yep, man page debian; [!] -o, --out-interface name Name of an interface via which a packet is going to be sent (for packets entering the FORWARD, OUTPUT and POSTROUTING chains). When the "!" argument is used before the interface name, the sense is inverted. If the interface name ends in a "...
-o in iptables is for specifying the interface for OUTPUT, FORWARD, and POSTROUTING Correct?
1,567,011,012,000
I have the following in nftables.conf: table inet nat { set blocked { type ipv4_addr } chain postrouting { type nat hook postrouting priority 100; policy accept; ip daddr @blocked counter drop; oifname "ppp0" masquerade; ...
The nat hook (as all other hooks) is provided by Netfilter to nftables. The NAT hook is special: only the first packet of a connection is traversing this hook. All other packets of a connection already tracked by conntrack aren't traversing any NAT hook anymore but are then directly handled by conntrack to continue pe...
nftables Named Set Update Delay
1,567,011,012,000
I have a following mangle table rule in a lab server which marks UDP traffic with 1 if the destination address is 6.6.6.6: $ sudo iptables -t mangle -L PREROUTING 2 -v -n --line-numbers 2 17 884 MARK udp -- ge-0.0.0-Iosv6 * 0.0.0.0/0 6.6.6.6 MARK set 0x1 $ 6.6.6.6/32 is c...
Here's a Packet flow in Netfilter and General Networking schematic: While the ingress packet was marked in PREROUTING, the locally generated reply packet did egress through OUTPUT: there's no rule to mark it there, so there's no mark and the route is different. Altering the packet in mangle/OUTPUT, including changing...
marked packets not detected by routing policy database
1,567,011,012,000
I have seen connmark or ctinfo could work for this but couldn't find a simple effective command to make it work (Not familiar within this area). The command can be applied to the TCP termination node or any linux node as intermediary router.
iptables -t mangle -A PREROUTING -m dscp --dscp-class AF12 -j CONNMARK --set-xmark 12 iptables -t mangle -A POSTROUTING -m connmark --mark 12 -j DSCP --set-dscp-class AF12 (not 100% dynamic as the DSCP value need to be known in advance in order to get a match)
Example command to set same DSCP value in the IP header for return packets within the same TCP connection
1,567,011,012,000
I have below nftable rule to add a connection rate meter: nft add rule ip filter input tcp dport @rate_limit meter syn4-meter \{ ip saddr . tcp dport timeout 5m limit rate 20/minute \} counter accept It generates the error: Error: syntax error, unexpected saddr, expecting comma or '}' add rule ip filter input tcp dp...
You have two problems: using a too old version of nftables. I could reproduce the error Error: syntax error, unexpected saddr, expecting comma or '}' using nftables version 0.7 (as found in Debian 9). Meters (nftables wiki) suggests nftables >= 0.8.1 and kernel >= 4.3. Upgrade nftables. Eg, on Debian 9, using the str...
nftables meter error: syntax error, unexpected saddr, expecting comma or '}'
1,567,011,012,000
conntrack match module --ctstate argument supports RELATED packet state. How does Netfilter know that for example in case of active FTP a connection from FTP server data port(TCP port 20) to the unprivileged data port the client specified earlier, is a RELATED connection? Does Netfilter have some modules where each pr...
Various Internet Control Message Protocol (ICMP) packets may be "related" to some protocol's connection (or an attempt at such), but these ICMP packets are different than the protocol that caused them, hence the "related" notion. This may happen when a host or firewall rejects a TCP or UDP connection attempt with a de...
How does Netfilter understand that packet is RELATED?
1,567,011,012,000
I am trying to use DNAT on a new custom Linux target, but I get an error with the following basic command: #iptables -t nat -A PREROUTING -d 10.110.0.250 -p tcp --dport 9090 -j DNAT --to 10.110.0.239:80 $iptables: No chain/target/match by that name. I think all modules are correctly loaded: # lsmod | grep ip ipt_MAS...
The problem was a missing module XT_TCPUDP There is the full list of dynamic loaded module for my command : xt_nat 1527 1 - Live 0xbf12f000 xt_tcpudp 1961 1 - Live 0xbf12b000 iptable_nat 2396 1 - Live 0xbf127000 nf_conntrack_ipv4 11354 1 - Live 0xbf120000 nf_defrag_ipv4 1331 1 nf_conntrack_ipv4, Live 0xbf11c000 nf_nat...
iptables DNAT: 'No chain/target/match by that name'
1,567,011,012,000
I'd like to take a default drop approach to my firewall rules. I've created some rules for testing purposes: table bridge vmbrfilter { chain forward { type filter hook forward priority -100; policy drop; ip saddr 192.168.1.10 ip daddr 192.168.1.1 accept; ip saddr 192.168.1.1 ip daddr 192.16...
IPv4 over Ethernet relies on ARP to resolve the Ethernet MAC address of the peer in order to send later unicast packets to it. As you're filtering any ARP request since there's no exception for it, those requests can't succeed and after a typical 3s timeout you'll get the standard "No route to host". There won't be an...
Nftables default drop chain problem
1,500,453,850,000
I am planning to use Shorewall to filter traffic that originates from a virtual interface created by OpenVPN (lets call it tap0). If OpenVPN did not successfully create this interface before Shorewall started, but the interface was defined in /etc/shorewall/interfaces, would traffic be filtered if the interface was s...
Shorewall is a tool for configuring iptables/netfilter firewall rules, so the documentation for netfilter is a more effective place to look. It says: It is perfectly legal to specify an interface that currently does not exist; the rule will not match anything until the interface comes up. This is extremely useful fo...
Shorewall to protect interfaces that are not yet defined
1,500,453,850,000
My linux home router sits between my ISP (Orange) and my home network. On the WAN side, Orange provide internet in a VLAN tagged 832. Some control messages (ARP, DHCP, ICMPv6 "router discovery" types, DHCPv6) need to be replied to Orange with: - VLAN priority = 6 - IPv4 or IPv6 DSCP = "CS6" (6 bits 0x30, or 48 in deci...
The source issue was a simple sequencing problem regarding the vlan interface. My network interface persistence file was initially misconfigured: # WAN vlan 832 internet auto enp1s0.832 iface enp1s0.832 inet dhcp up ip link set enp1s0.832 type vlan egress 0:0 1:0 2:0 3:0 4:0 5:0 6:6 7:0 iface enp1s0.832 inet6 dhcp ...
Packet meta class applied, but captured VLAN priority is wrong
1,500,453,850,000
I understand that iptables --set-mark does not add mark "on" the packets. The MARK target is for associating a mark with the packet in the kernel data structures. The packet itself is not modified. But is there any way to view the packet with its associated mark? We can see ctmark (connection marks which are set using...
The question is about the fwmark or just mark (historically named nfmark but renamed to just mark at the same time it didn't depend anymore on netfilter. The word nfmark is now a bit misleading, but still present in a few places which weren't or couldn't be updated). This mark is done on the packet's skbuff, while the...
Is there any way to view nfmark like ctmark?
1,500,453,850,000
An article at this URI https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security_guide/sect-security_guide-firewalls-iptables_and_connection_tracking RELATED — A packet that is requesting a new connection but is part of an existing connection. For example, FTP uses port 21 to establish a ...
Does it go through the FTP messages to find out the data-connection tuple (dst_ip, dst_prt, src_ip, src_prt) ? I know that is way too impractical to implement. Yes, that is exactly what it does. Why do you think it's too impractical? You can look at the code yourself here: https://git.kernel.org/pub/scm/linux/kernel...
How is netfilter able to track the out-of-band data-connections of FTP to be in RELATED state with control-connection?
1,500,453,850,000
iptables. I have went though the manual of Iptables and known some basic concepts, e.g. chain, table, hook, rule and targets. In the Linux ecosystem, iptables is a widely used firewall tool that interfaces with the kernel’s netfilter packet filtering framework. route table. In Linux, there is another table route tab...
In both "route" steps. One is for incoming packets, one for packets created from local applications. Note that iptables and routing are intended for two totally different concepts: Routing answers the question "where should this packet be delivered to?", while iptables answers the question "do I need to filter or some...
During the lifecycle of "iptables", in which step, will kernel take advantage of "route table"?
1,500,453,850,000
This is on Ubuntu 20.04. I am attempting to write a rule for nftables which will match all IP packets received on interface eth1 that have a specific TOS value (0x02). My attempt so far: sudo nft add table raw sudo nft -- add chain raw prerouting {type filter hook prerouting priority -300\;} sudo nft add rule ip raw p...
Looking further into the make-up of a IPv4 header: https://en.wikipedia.org/wiki/IPv4#Header I see that TOS is the name given to the entire byte, but DSCP is the name for only the most-significant 6 bits. Based on this I guessed TOS != DSCP. I tried changing the sending code to using a TOS of 0x20 and then modified th...
Nftables not matching TOS value in IP packets
1,500,453,850,000
This question is frequent and has already a lot of answers, but I still don't get it. Is the routing configured with "ip route add .." part of the iptables flow? Is the "routing decision" like in the following picture the routing table configured with "ip route"?
I don't claim to know the source code for Linux kernel networking and Netfilter, but here's how I understand it. Is the routing configured with "ip route add .." part of the iptables flow? The short answer is yes. See below for a longer answer. Is the "routing decision" like in the following picture the routing table...
routing table configured with "ip route" part of the "iptables"?
1,500,453,850,000
I'd like to add a rule dropping an IPv4 packet with any IP option following the header. I understand that IHL (Internet Header Length) field in he header contains the number of 32-bit words in the IPv4 header, including options. So, my understanding is that a rule should obtain the packet+options length from IHL field...
iptables includes the u32 match method which allows to do some bitwise (but not arbitrary arithmetic) operations, range comparisons and some pointer-like indirections on packet payload to match conditions: u32 U32 tests whether quantities of up to 4 bytes extracted from a packet have specified values. The specificati...
netfilter: drop packets having IP options
1,500,453,850,000
From the nftables Quick reference: family refers to a one of the following table types: ip, arp, ip6, bridge, inet, netdev. and type refers to the kind of chain to be created. Possible types are: filter: Supported by arp, bridge, ip, ip6 and inet table families. route: Mark packets (like mangle for the output hook,...
I am new one, but also interested in nftables rules. I found in nftables wiki: "The principal (only?) use for this (netdev) family is for base chains using the ingress hook, new in Linux kernel 4.2." More info here, in the end of article: https://wiki.nftables.org/wiki-nftables/index.php/Nftables_families Ingress hook...
What chain types are supported by the nftables NETDEV family?
1,500,453,850,000
I have added a DNAT entry (in the host) for a port (say 30001) in PREROUTING using iptables $ sudo iptables -t nat -A PREROUTING -p tcp --dport 30001 -j DNAT --to-destination <my guest vm ip>:80 Note: Above I have tried a port forwarding technique to allow ingress to guest vm. Is it possible for a host process to bin...
Yes, binding a port is part of the network stack, which is separate from netfilter where iptables belongs to. netfilter will not care or be aware of this new listening port and the network stack will not be informed that there will be something special about it done in its back later. So it's fine to have a process bi...
Is it possible to bind to a port that has a entry for DNAT in iptables?